Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Nov 14, 2024

Delegator was needed to install command methods to frozen objects, but we don't do it anymore.

Dropping delegator will fix this weird behavior.

irb(main):001> cd 1
irb(1):002> self
=> 1
irb(1):003> frozen?
=> false
irb(1):004> self.class
=> SimpleDelegator
irb(1):005> { self => 1, 1 => 1 }
=> {1=>1, 1=>1}

Helper methods will be unavailable on frozen main object. However, I think it makes sense that frozen object can't have helper methods.
(We can change this by adding helper methods to Kernel instead of main object maybe in the future. It will also completely fix helper method polluting main object.)

This pull request also adds minimal support for BasicObject because the original delegator code was checking BasicObject.

case @main
when Object
  use_delegator = @main.frozen?
else
  use_delegator = true # main is BasicObject
end

IRB used delegator to install command as a method of frozen main object.
Command is not a method now. We can drop it.
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Thanks. There are some refactors that I think can be done but I'll give them a try in a separate PR.

@st0012 st0012 merged commit 2f1c593 into ruby:master Nov 19, 2024
28 of 30 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 19, 2024
object
(ruby/irb#1031)

IRB used delegator to install command as a method of frozen main object.
Command is not a method now. We can drop it.

ruby/irb@2f1c593801
@tompng tompng deleted the no_delegator branch November 19, 2024 13:21
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.

2 participants