summaryrefslogtreecommitdiff
path: root/lib/coderay/tokens_proxy.rb
blob: 598ad2e784dd20646871aeec9b3cac4012f99c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module CodeRay
  
  class TokensProxy < Struct.new :code, :lang, :options, :block
    
    def method_missing method, *args, &blk
      tokens.send(method, *args, &blk)
    end
    
    def tokens
      @tokens ||= scanner.tokenize(code)
    end
    
    def each *args, &blk
      tokens.each(*args, &blk)
    end
    
    def count
      tokens.count
    end
    
    def scanner
      @scanner ||= CodeRay.scanner(lang, options, &block)
    end
    
  end
  
end