mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix ls on Fixnum [Fixes #1120]
This commit is contained in:
parent
9c6db5ea1a
commit
a01265881d
3 changed files with 15 additions and 6 deletions
|
@ -10,9 +10,8 @@ module Pry::Command::Ls::Interrogateable
|
||||||
if interrogating_a_module?
|
if interrogating_a_module?
|
||||||
@interrogatee
|
@interrogatee
|
||||||
else
|
else
|
||||||
class << @interrogatee
|
singleton = Pry::Method.singleton_class_of(@interrogatee)
|
||||||
ancestors.grep(::Class).reject { |c| c == self }.first
|
singleton.ancestors.grep(::Class).reject { |c| c == singleton }.first
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -192,8 +192,6 @@ class Pry
|
||||||
/^define_method\(?\s*[:\"\']#{Regexp.escape(name)}|^def\s*#{Regexp.escape(name)}/ =~ definition_line.strip
|
/^define_method\(?\s*[:\"\']#{Regexp.escape(name)}|^def\s*#{Regexp.escape(name)}/ =~ definition_line.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# Get the singleton classes of superclasses that could define methods on
|
# Get the singleton classes of superclasses that could define methods on
|
||||||
# the given class object, and any modules they include.
|
# the given class object, and any modules they include.
|
||||||
# If a module is included at multiple points in the ancestry, only
|
# 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
|
resolution_order.reverse.uniq.reverse - Class.included_modules
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.
|
# A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.
|
||||||
|
|
|
@ -47,6 +47,12 @@ describe "ls" do
|
||||||
end
|
end
|
||||||
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
|
describe "methods" do
|
||||||
it "should show public methods by default" do
|
it "should show public methods by default" do
|
||||||
output = pry_eval("ls Class.new{ def goo; end; public :goo }.new")
|
output = pry_eval("ls Class.new{ def goo; end; public :goo }.new")
|
||||||
|
|
Loading…
Add table
Reference in a new issue