Fix ls on Fixnum [Fixes #1120]

This commit is contained in:
Conrad Irwin 2014-02-05 15:32:45 -08:00
parent 9c6db5ea1a
commit a01265881d
3 changed files with 15 additions and 6 deletions

View File

@ -10,9 +10,8 @@ module Pry::Command::Ls::Interrogateable
if interrogating_a_module?
@interrogatee
else
class << @interrogatee
ancestors.grep(::Class).reject { |c| c == self }.first
end
singleton = Pry::Method.singleton_class_of(@interrogatee)
singleton.ancestors.grep(::Class).reject { |c| c == singleton }.first
end
end

View File

@ -192,8 +192,6 @@ class Pry
/^define_method\(?\s*[:\"\']#{Regexp.escape(name)}|^def\s*#{Regexp.escape(name)}/ =~ definition_line.strip
end
private
# Get the singleton classes of superclasses that could define methods on
# the given class object, and any modules they include.
# If a module is included at multiple points in the ancestry, only
@ -207,7 +205,13 @@ class Pry
resolution_order.reverse.uniq.reverse - Class.included_modules
end
def singleton_class_of(obj); class << obj; self; end end
def singleton_class_of(obj)
begin
class << obj; self; end
rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ...
obj.class
end
end
end
# A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.

View File

@ -47,6 +47,12 @@ describe "ls" do
end
end
describe "immediates" do
it "should work on Fixnum" do
pry_eval("ls 5").should =~ /Fixnum#methods:.*modulo/m
end
end
describe "methods" do
it "should show public methods by default" do
output = pry_eval("ls Class.new{ def goo; end; public :goo }.new")