mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/rdoc] fix: Fix NoMethodError for tokens_to_s
method
Calling `tokens_to_s` gets an error if `token_stream` is nil:
```
undefined method `compact' for nil:NilClass (NoMethodError)
```
So, fall back to an empty array if `@token_stream` is nil.
452e4a2600
This commit is contained in:
parent
d2e7a70ee6
commit
72242e69aa
2 changed files with 10 additions and 1 deletions
|
@ -105,7 +105,7 @@ module RDoc::TokenStream
|
||||||
# Current token stream
|
# Current token stream
|
||||||
|
|
||||||
def token_stream
|
def token_stream
|
||||||
@token_stream
|
@token_stream || []
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -53,5 +53,14 @@ class TestRDocTokenStream < RDoc::TestCase
|
||||||
end.new
|
end.new
|
||||||
|
|
||||||
assert_equal "foo 'bar'", foo.tokens_to_s
|
assert_equal "foo 'bar'", foo.tokens_to_s
|
||||||
|
|
||||||
|
foo = Class.new do
|
||||||
|
include RDoc::TokenStream
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@token_stream = nil
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
assert_equal "", foo.tokens_to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue