diff --git a/lib/pry/code_object.rb b/lib/pry/code_object.rb index 6575a8d7..078fa0b7 100644 --- a/lib/pry/code_object.rb +++ b/lib/pry/code_object.rb @@ -70,7 +70,9 @@ class Pry if str !~ /\S#\S/ && target.eval("defined? #{str} ") =~ /variable|constant/ obj = target.eval(str) - if obj.respond_to?(:source_location) + # restrict to only objects we KNOW for sure support the full API + # Do NOT support just any object that responds to source_location + if [::Proc, ::Method, ::UnboundMethod].any? { |o| obj.is_a?(o) } Pry::Method(obj) elsif !obj.is_a?(Module) Pry::WrappedModule(obj.class) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index d30e8b8c..45ea5100 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -506,6 +506,30 @@ class Pry # gems your command needs to run, or to set up state. class ClassCommand < Command + class << self + def source + Pry::WrappedModule(self).source + end + + def doc + new.help + end + + def source_location + Pry::WrappedModule(self).source_location + end + + def source_file + Pry::WrappedModule(self).source_file + end + alias_method :file, :source_file + + def source_line + Pry::WrappedModule(self).source_line + end + alias_method :line, :source_line + end + # The class that couples together subcommands and top-level options (that # are known as "default" options). The explicitly defined instance methods # of this class provide the coupling with default options of a