Skip to content
Merged
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
15 changes: 15 additions & 0 deletions core/method/original_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@
obj.method(:baz).original_name.should == :foo
obj.method(:baz).unbind.bind(obj).original_name.should == :foo
end

it "returns the source UnboundMethod's name (not the name given to define_method)" do
klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
klass.new.method(:my_inspect).original_name.should == :inspect
end

it "preserves the source method's name through define_method and alias" do
source = Class.new { def my_method; end }
klass = Class.new(source) do
define_method(:renamed, source.instance_method(:my_method))
alias aliased renamed
end
klass.new.method(:renamed).original_name.should == :my_method
klass.new.method(:aliased).original_name.should == :my_method
end
end
15 changes: 15 additions & 0 deletions core/unboundmethod/original_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@
obj.method(:baz).unbind.original_name.should == :foo
UnboundMethodSpecs::Methods.instance_method(:baz).original_name.should == :foo
end

it "returns the source UnboundMethod's name (not the name given to define_method)" do
klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
klass.instance_method(:my_inspect).original_name.should == :inspect
end

it "preserves the source method's name through define_method and alias" do
source = Class.new { def my_method; end }
klass = Class.new(source) do
define_method(:renamed, source.instance_method(:my_method))
alias aliased renamed
end
klass.instance_method(:renamed).original_name.should == :my_method
klass.instance_method(:aliased).original_name.should == :my_method
end
end