Skip to content

Conversation

@casperisfine
Copy link

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.

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.
@hsbt hsbt merged commit 52d2b86 into ruby:master Nov 12, 2024
@hsbt hsbt mentioned this pull request Nov 12, 2024
st0012 added a commit to ruby/irb that referenced this pull request Dec 18, 2024
`pp` 0.6.0+ includes ruby/pp#26 to handle BasicObject,
so we can drop the workaround.
st0012 added a commit to ruby/irb that referenced this pull request Jan 11, 2025
`pp` 0.6.0+ includes ruby/pp#26 to handle BasicObject,
so we can drop the workaround.
st0012 added a commit to ruby/irb that referenced this pull request Jan 11, 2025
`pp` 0.6.0+ includes ruby/pp#26 to handle BasicObject,
so we can drop the workaround.
tompng pushed a commit to ruby/irb that referenced this pull request Jan 12, 2025
`pp` 0.6.0+ includes ruby/pp#26 to handle BasicObject,
so we can drop the workaround.
matzbot pushed a commit to ruby/ruby that referenced this pull request Jan 12, 2025
(ruby/irb#1051)

`pp` 0.6.0+ includes ruby/pp#26 to handle BasicObject,
so we can drop the workaround.

ruby/irb@08908d43c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants