Skip to content

Commit

Permalink
Use binding.receiver instead of binding.eval("self")
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Nov 14, 2024
1 parent a6fae8b commit 5ee47f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ class RegexpCompletor < BaseCompletor # :nodoc:
using Module.new {
refine ::Binding do
def eval_methods
::Kernel.instance_method(:methods).bind(eval("self")).call
::Kernel.instance_method(:methods).bind_call(receiver)
end

def eval_private_methods
::Kernel.instance_method(:private_methods).bind(eval("self")).call
::Kernel.instance_method(:private_methods).bind_call(receiver)
end

def eval_instance_variables
::Kernel.instance_method(:instance_variables).bind(eval("self")).call
::Kernel.instance_method(:instance_variables).bind_call(receiver)
end

def eval_global_variables
::Kernel.instance_method(:global_variables).bind(eval("self")).call
::Kernel.instance_method(:global_variables).bind_call(receiver)
end

def eval_class_constants
::Module.instance_method(:constants).bind(eval("self.class")).call
::Module.instance_method(:constants).bind_call(receiver.class)
end
end
}
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def initialize(*main)
end

if main.empty?
@main = eval("self", @binding)
@main = @binding.receiver
else
@main = main[0]
end
Expand Down

0 comments on commit 5ee47f3

Please sign in to comment.