Pretty Prettying a SimpleDelegator object which implements `#inspect` doesn't work
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 36
- Forks
- 21
- Avg merge
- 8h 22m
- Merged PRs (30d)
- 1
Description
Hey there!
I come across this weird bug(?) when I was trying to inspect an object in irb. Since irb uses pp to print the objects I'm opening this issue here.
In my case I have a class that inherits from SimpleDelegator:
require "delegate"
class Parent
def inspect
"<parent>"
end
end
class Child < SimpleDelegator
def inspect
"<child>"
end
end
In irb I noticed it because the objects are being shown using inspect:
irb(main):001> Parent.new.inspect
# => "<parent>"
irb(main):002> Parent.new
# => <parent>
irb(main):003> Child.new(Parent.new).inspect
# => "<child>"
irb(main):004> Child.new(Parent.new)
# => <parent>
Personally, I would have expected the last one to also show <child>. Now after digging into this a bit more (thanks @st0012), it seems like you can also reproduce this in pp directly using:
require "delegate"
require "pp"
class Parent
def inspect
"<parent>"
end
end
class Child < SimpleDelegator
def inspect
"<child>"
end
end
parent = Parent.new
child = Child.new(parent)
pp child
#=> "<parent>"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Ruby reproduction with delegate and pp, then compare the behavior of Parent and Child when printed. Read the PrettyPrinter behavior around SimpleDelegator and custom inspect; done means the intended child representation is printed consistently without breaking ordinary delegation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100