Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/method/original_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@
klass.new.method(:renamed).original_name.should == :my_method
klass.new.method(:aliased).original_name.should == :my_method
end

it "returns the source UnboundMethod's name for Kernel#is_a? and Kernel#kind_of?" do
klass = Class.new { define_method(:is_a?, ::Kernel.instance_method(:is_a?)) }
klass.new.method(:is_a?).original_name.should == :is_a?

klass = Class.new { define_method(:kind_of?, ::Kernel.instance_method(:kind_of?)) }
klass.new.method(:kind_of?).original_name.should == :kind_of?
end

it "preserves the source name when aliasing a define_method'd Kernel method" do
klass = Class.new do
define_method(:is_a?, ::Kernel.instance_method(:is_a?))
alias_method :renamed_is_a?, :is_a?
end
klass.new.method(:renamed_is_a?).original_name.should == :is_a?
end
end
26 changes: 26 additions & 0 deletions core/method/shared/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,30 @@ def obj.bar; end
it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
end

it "shows the original name in parentheses for an aliased method" do
klass = Class.new do
def original_method; end
alias_method :renamed_is_a?, :original_method
end
klass.new.method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(original_method\)/
end

it "shows the source UnboundMethod's name in parentheses for a define_method'd method" do
klass = Class.new { define_method(:renamed_is_a?, ::Kernel.instance_method(:is_a?)) }
klass.new.method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/
end

it "does not annotate a directly looked-up Kernel method with a shared internal name" do
Object.new.method(:is_a?).send(@method).should_not =~ /\(kind_of\?\)/
Object.new.method(:kind_of?).send(@method).should_not =~ /\(is_a\?\)/
end

it "shows the source name when aliasing a define_method'd Kernel method" do
klass = Class.new do
define_method(:is_a?, ::Kernel.instance_method(:is_a?))
alias_method :renamed_is_a?, :is_a?
end
klass.new.method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/
end
end
16 changes: 16 additions & 0 deletions core/unboundmethod/original_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@
klass.instance_method(:renamed).original_name.should == :my_method
klass.instance_method(:aliased).original_name.should == :my_method
end

it "returns the source UnboundMethod's name for Kernel#is_a? and Kernel#kind_of?" do
klass = Class.new { define_method(:is_a?, ::Kernel.instance_method(:is_a?)) }
klass.instance_method(:is_a?).original_name.should == :is_a?

klass = Class.new { define_method(:kind_of?, ::Kernel.instance_method(:kind_of?)) }
klass.instance_method(:kind_of?).original_name.should == :kind_of?
end

it "preserves the source name when aliasing a define_method'd Kernel method" do
klass = Class.new do
define_method(:is_a?, ::Kernel.instance_method(:is_a?))
alias_method :renamed_is_a?, :is_a?
end
klass.instance_method(:renamed_is_a?).original_name.should == :is_a?
end
end
26 changes: 26 additions & 0 deletions core/unboundmethod/shared/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,30 @@
it "does not show the defining module if it is the same as the origin" do
UnboundMethodSpecs::A.instance_method(:baz).send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::A#baz"
end

it "shows the original name in parentheses for an aliased method" do
klass = Class.new do
def original_method; end
alias_method :renamed_is_a?, :original_method
end
klass.instance_method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(original_method\)/
end

it "shows the source UnboundMethod's name in parentheses for a define_method'd method" do
klass = Class.new { define_method(:renamed_is_a?, ::Kernel.instance_method(:is_a?)) }
klass.instance_method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/
end

it "does not annotate a directly looked-up Kernel method with a shared internal name" do
Object.instance_method(:is_a?).send(@method).should_not =~ /\(kind_of\?\)/
Object.instance_method(:kind_of?).send(@method).should_not =~ /\(is_a\?\)/
end

it "shows the source name when aliasing a define_method'd Kernel method" do
klass = Class.new do
define_method(:is_a?, ::Kernel.instance_method(:is_a?))
alias_method :renamed_is_a?, :is_a?
end
klass.instance_method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/
end
end
Loading