diff options
Diffstat (limited to 'lib/coderay/tokens_proxy.rb')
-rw-r--r-- | lib/coderay/tokens_proxy.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/coderay/tokens_proxy.rb b/lib/coderay/tokens_proxy.rb new file mode 100644 index 0000000..598ad2e --- /dev/null +++ b/lib/coderay/tokens_proxy.rb @@ -0,0 +1,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 |