Class | CodeRay::TokensProxy |
In: |
lib/coderay/tokens_proxy.rb
|
Parent: | Object |
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.
block | [RW] | |
input | [RW] | |
lang | [RW] | |
options | [RW] |
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