diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2013-04-25 01:09:06 -0700 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2013-04-25 01:09:06 -0700 |
commit | ab4cc3d8262222228a80646b63cd6a3bff5c82d5 (patch) | |
tree | 80a75082661d025d6b10cdc0cfe364515eac1d06 | |
parent | b888d557e924adb00672286147ed90447a2b769f (diff) | |
download | pry-ab4cc3d8262222228a80646b63cd6a3bff5c82d5.tar.gz |
Allow frozen_object.pry
-rw-r--r-- | lib/pry.rb | 9 | ||||
-rw-r--r-- | lib/pry/core_extensions.rb | 2 | ||||
-rw-r--r-- | spec/pry_spec.rb | 5 |
3 files changed, 15 insertions, 1 deletions
@@ -182,6 +182,15 @@ class Pry 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 DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException, Pry::TooSafeException] diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb index c86d83b5..db4b0776 100644 --- a/lib/pry/core_extensions.rb +++ b/lib/pry/core_extensions.rb @@ -89,7 +89,7 @@ class Object # 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 # 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 self.class.class_eval(*Pry::BINDING_METHOD_IMPL) end diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb index 1082b8ed..09a199d2 100644 --- a/spec/pry_spec.rb +++ b/spec/pry_spec.rb @@ -64,6 +64,11 @@ describe Pry do Pry.binding_for(obj).eval("local_variables").should.be.empty end end + + it "should work on frozen objects" do + a = "hello".freeze + Pry.binding_for(a).eval("self").should.equal? a + end end describe "open a Pry session on an object" do |