From a6b256219d84022fc518d620b210754b5f8ccce4 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 18 Sep 2011 22:24:06 +0200 Subject: #352 CodeRay.scan returns TokensProxy --- lib/coderay/tokens_proxy.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/coderay/tokens_proxy.rb (limited to 'lib/coderay/tokens_proxy.rb') 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 -- cgit v1.2.1