зеркало из https://github.com/github/ruby.git
Handle binding.irb for frozen objects and BasicObjects using a delegate
Fixes Ruby Bug 13264
This commit is contained in:
Родитель
caeafbe825
Коммит
7d9c3a5712
|
@ -9,6 +9,9 @@
|
|||
#
|
||||
#
|
||||
#
|
||||
|
||||
require "delegate"
|
||||
|
||||
module IRB # :nodoc:
|
||||
class WorkSpace
|
||||
# Creates a new workspace.
|
||||
|
@ -55,11 +58,15 @@ EOF
|
|||
__LINE__ - 3)
|
||||
end
|
||||
end
|
||||
|
||||
if main.empty?
|
||||
@main = eval("self", @binding)
|
||||
else
|
||||
@main = main[0]
|
||||
IRB.conf[:__MAIN__] = @main
|
||||
end
|
||||
IRB.conf[:__MAIN__] = @main
|
||||
|
||||
unless main.empty?
|
||||
case @main
|
||||
when Module
|
||||
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
||||
|
@ -71,6 +78,28 @@ EOF
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
case @main
|
||||
when Object
|
||||
use_delegator = @main.frozen?
|
||||
else
|
||||
use_delegator = true
|
||||
end
|
||||
|
||||
if use_delegator
|
||||
@main = SimpleDelegator.new(@main)
|
||||
IRB.conf[:__MAIN__] = @main
|
||||
@main.singleton_class.class_eval do
|
||||
private
|
||||
define_method(:exit) do |*a, &b|
|
||||
# Do nothing, will be overridden
|
||||
end
|
||||
define_method(:binding, Kernel.instance_method(:binding))
|
||||
define_method(:local_variables, Kernel.instance_method(:local_variables))
|
||||
end
|
||||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
|
||||
end
|
||||
|
||||
@binding.local_variable_set(:_, nil)
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче