mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Allow frozen_object.pry
This commit is contained in:
parent
b888d557e9
commit
ab4cc3d826
3 changed files with 15 additions and 1 deletions
|
@ -182,6 +182,15 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# When we try to get a binding for an object, we try to define a method on
|
||||||
|
# that Object's singleton class. This doesn't work for "frozen" Object's, and
|
||||||
|
# the exception is just a vanilla RuntimeError.
|
||||||
|
module FrozenObjectException
|
||||||
|
def self.===(exception)
|
||||||
|
exception.message == (Pry::Helpers::BaseHelpers.jruby? ? "can't modify frozen class/module" : "can't modify frozen Class")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Don't catch these exceptions
|
# Don't catch these exceptions
|
||||||
DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException, Pry::TooSafeException]
|
DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException, Pry::TooSafeException]
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class Object
|
||||||
# If we can't define methods on the Object's singleton_class. Then we fall
|
# If we can't define methods on the Object's singleton_class. Then we fall
|
||||||
# back to setting the default definee to be the Object's class. That seems
|
# back to setting the default definee to be the Object's class. That seems
|
||||||
# nicer than having a REPL in which you can't define methods.
|
# nicer than having a REPL in which you can't define methods.
|
||||||
rescue TypeError
|
rescue TypeError, Pry::FrozenObjectException
|
||||||
# class_eval sets the default definee to self.class
|
# class_eval sets the default definee to self.class
|
||||||
self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
|
self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,11 @@ describe Pry do
|
||||||
Pry.binding_for(obj).eval("local_variables").should.be.empty
|
Pry.binding_for(obj).eval("local_variables").should.be.empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should work on frozen objects" do
|
||||||
|
a = "hello".freeze
|
||||||
|
Pry.binding_for(a).eval("self").should.equal? a
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "open a Pry session on an object" do
|
describe "open a Pry session on an object" do
|
||||||
|
|
Loading…
Reference in a new issue