Skip to content

Commit 604dc16

Browse files
fix: fix NoMethodError when token_stream is nil
The change in #1055 might be a breaking change. So, just simply wrap `token_stream` with `Array` Co-authored-by: Jonathan Hefner <[email protected]>
1 parent 72897d3 commit 604dc16

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/rdoc/token_stream.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ def pop_token
105105
# Current token stream
106106

107107
def token_stream
108-
@token_stream || []
108+
@token_stream
109109
end
110110

111111
##
112112
# Returns a string representation of the token stream
113113

114114
def tokens_to_s
115-
token_stream.compact.map { |token| token[:text] }.join ''
115+
Array(token_stream).compact.map { |token| token[:text] }.join ''
116116
end
117117

118118
end

test/rdoc/test_rdoc_token_stream.rb

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def test_class_to_html_empty
3939
assert_equal '', RDoc::TokenStream.to_html([])
4040
end
4141

42+
def test_token_stream
43+
foo = Class.new do
44+
include RDoc::TokenStream
45+
end.new
46+
assert_equal nil, foo.token_stream
47+
end
48+
4249
def test_tokens_to_s
4350
foo = Class.new do
4451
include RDoc::TokenStream

0 commit comments

Comments
 (0)