The result of a scan operation is a TokensProxy, but should act like Tokens.
This proxy makes it possible to use the classic CodeRay.scan.encode API while still providing the benefits of direct streaming.
Create a new TokensProxy with the arguments of CodeRay.scan.
# File lib/coderay/tokens_proxy.rb, line 12 12: def initialize input, lang, options = {}, block = nil 13: @input = input 14: @lang = lang 15: @options = options 16: @block = block 17: end
Overwrite Struct#each.
# File lib/coderay/tokens_proxy.rb, line 48 48: def each *args, &blk 49: tokens.each(*args, &blk) 50: self 51: end
Call CodeRay.encode if encoder is a Symbol; otherwise, convert the receiver to tokens and call encoder.encode_tokens.
# File lib/coderay/tokens_proxy.rb, line 21 21: def encode encoder, options = {} 22: if encoder.respond_to? :to_sym 23: CodeRay.encode(input, lang, encoder, options) 24: else 25: encoder.encode_tokens tokens, options 26: end 27: end
Tries to call encode; delegates to tokens otherwise.
# File lib/coderay/tokens_proxy.rb, line 31 31: def method_missing method, *args, &blk 32: encode method.to_sym, *args 33: rescue PluginHost::PluginNotFound 34: tokens.send(method, *args, &blk) 35: end
A (cached) scanner instance to use for the scan task.
# File lib/coderay/tokens_proxy.rb, line 43 43: def scanner 44: @scanner ||= CodeRay.scanner(lang, options, &block) 45: end
The (cached) result of the tokenized input; a Tokens instance.
# File lib/coderay/tokens_proxy.rb, line 38 38: def tokens 39: @tokens ||= scanner.tokenize(input) 40: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.