Skip to content

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Mar 13, 2023

When inspecting BasicObject in irb, the default inspector pp would raise an exception because it calls is_a? on the object. We should help pp support BasicObject (if that's possible), but in the meantime we can also mitigate the problem from irb.

Closes #540

@st0012 st0012 added the bug Something isn't working label Mar 13, 2023
@st0012 st0012 self-assigned this Mar 13, 2023
class ColorPrinter < ::PP
METHOD_IS_A = Object.instance_method(:is_a?)
METHOD_RESPOND_TO = Object.instance_method(:respond_to?)
METHOD_INSPECT = Object.instance_method(:inspect)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we already have store the method object in other places (e.g. inspector.rb). But I don't want to create dependencies between files just to reuse this as it's easy to find duplications later on.

@st0012 st0012 requested a review from a team March 13, 2023 05:58
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

irb(main):001:0> BasicObject.new
=> #<BasicObject:0x0000000103e59788>
irb(main):002:0> [BasicObject.new]
=> [#<BasicObject:0x0000000103eba038>]

🎉 Looks good to me 👍

@tompng tompng merged commit 1dc2a40 into master Mar 13, 2023
@tompng tompng deleted the fix-#540 branch March 13, 2023 14:31
matzbot pushed a commit to ruby/ruby that referenced this pull request Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix basic object no method error

3 participants