Skip to content

Commit f4a43f6

Browse files
committed
TokensProxy cleanup; #each returns self
1 parent cec235c commit f4a43f6

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/coderay/tokens_proxy.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ module CodeRay
22

33
class TokensProxy < Struct.new :input, :lang, :options, :block
44

5+
def encode encoder, options = {}
6+
if encoder.respond_to? :to_sym
7+
CodeRay.encode(input, lang, encoder, options)
8+
else
9+
encoder.encode_tokens tokens, options
10+
end
11+
end
12+
513
def method_missing method, *args, &blk
614
encode method, *args
715
rescue PluginHost::PluginNotFound
@@ -12,26 +20,19 @@ def tokens
1220
@tokens ||= scanner.tokenize(input)
1321
end
1422

23+
def scanner
24+
@scanner ||= CodeRay.scanner(lang, options, &block)
25+
end
26+
1527
def each *args, &blk
1628
tokens.each(*args, &blk)
29+
self
1730
end
1831

1932
def count
2033
tokens.count
2134
end
2235

23-
def scanner
24-
@scanner ||= CodeRay.scanner(lang, options, &block)
25-
end
26-
27-
def encode encoder, options = {}
28-
if encoder.respond_to? :to_sym
29-
CodeRay.encode(input, lang, encoder, options)
30-
else
31-
encoder.encode_tokens tokens, options
32-
end
33-
end
34-
3536
end
3637

3738
end

0 commit comments

Comments
 (0)