mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Show something for anonymous classes. [Fixes #366]
This commit is contained in:
parent
36d685f71f
commit
778c50316f
2 changed files with 21 additions and 2 deletions
|
@ -20,12 +20,23 @@ class Pry
|
|||
def method_prefix
|
||||
if singleton_class?
|
||||
if Module === singleton_instance
|
||||
"#{singleton_instance.name}."
|
||||
"#{WrappedModule.new(singleton_instance).nonblank_name}."
|
||||
else
|
||||
"self."
|
||||
end
|
||||
else
|
||||
"#{name}#"
|
||||
"#{nonblank_name}#"
|
||||
end
|
||||
end
|
||||
|
||||
# The name of the Module if it has one, otherwise #<Class:0xf00>.
|
||||
#
|
||||
# @return [String]
|
||||
def nonblank_name
|
||||
if name.to_s == ""
|
||||
wrapped.inspect
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,6 +33,14 @@ describe Pry::WrappedModule do
|
|||
describe "of singleton classes of objects" do
|
||||
Pry::WrappedModule.new(class << @foo; self; end).method_prefix.should == "self."
|
||||
end
|
||||
|
||||
describe "of anonymous classes should not be empty" do
|
||||
Pry::WrappedModule.new(Class.new).method_prefix.should =~ /#<Class:.*>#/
|
||||
end
|
||||
|
||||
describe "of singleton classes of anonymous classes should not be empty" do
|
||||
Pry::WrappedModule.new(class << Class.new; self; end).method_prefix.should =~ /#<Class:.*>./
|
||||
end
|
||||
end
|
||||
|
||||
describe ".singleton_class?" do
|
||||
|
|
Loading…
Add table
Reference in a new issue