mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
[ruby/pp] Handle BasicObject
Right now attempting to pretty print a BasicObject or any other
object lacking a few core Object methods will result in an error
```
Error: test_basic_object(PPTestModule::PPInspectTest): NoMethodError: undefined method `is_a?' for an instance of BasicObject
lib/pp.rb:192:in `pp'
lib/pp.rb:97:in `block in pp'
lib/pp.rb:158:in `guard_inspect_key'
lib/pp.rb:97:in `pp'
test/test_pp.rb:131:in `test_basic_object'
128:
129: def test_basic_object
130: a = BasicObject.new
=> 131: assert_match(/\A#<BasicObject:0x[\da-f]+>\n\z/, PP.pp(a, ''.dup))
132: end
133: end
134:
```
With some fairly small changes we can fallback to `Object#inspect`
which is better than an error.
4e9f6c2de0
This commit is contained in:
parent
107a4da122
commit
83702f7157
2 changed files with 11 additions and 2 deletions
|
@ -125,6 +125,11 @@ class PPInspectTest < Test::Unit::TestCase
|
|||
result = PP.pp(a, ''.dup)
|
||||
assert_equal("#{a.inspect}\n", result)
|
||||
end
|
||||
|
||||
def test_basic_object
|
||||
a = BasicObject.new
|
||||
assert_match(/\A#<BasicObject:0x[\da-f]+>\n\z/, PP.pp(a, ''.dup))
|
||||
end
|
||||
end
|
||||
|
||||
class PPCycleTest < Test::Unit::TestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue