Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ca5e847e66d3
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6370559f16f9
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jul 22, 2015

  1. Implement {Method,UnboundMethod}#super_method

    The implementation relies on Module#direct_superclass to run through the
    whole ancestry chain as #superclass would not include the modules.
    
    The method is about 2 times slower than the MRI implementation though.
    Benchmark: http://git.io/vmhpf.
    robin850 committed Jul 22, 2015
    Copy the full SHA
    493847b View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6370559 View commit details
28 changes: 28 additions & 0 deletions kernel/common/method.rb
Original file line number Diff line number Diff line change
@@ -158,6 +158,20 @@ def unbind
UnboundMethod.new(@defined_in, @executable, @receiver.class, @name)
end

def super_method
superclass = @defined_in.direct_superclass

if superclass
mod, entry = superclass.lookup_method(@name)

if entry && entry.visibility != :undef
return Method.new(@receiver, superclass, entry.method, @name)
end
end

return nil
end

end

##
@@ -288,4 +302,18 @@ def owner
@defined_in
end
end

def super_method
superclass = @defined_in.direct_superclass

if superclass
mod, entry = superclass.lookup_method(@name)

if entry && entry.visibility != :undef
return UnboundMethod.new(superclass, entry.method, @defined_in, @name)
end
end

return nil
end
end
14 changes: 14 additions & 0 deletions spec/ruby/core/method/super_method_spec.rb
Original file line number Diff line number Diff line change
@@ -22,4 +22,18 @@
sss_meth.receiver.should == obj
sss_meth.name.should == :overridden
end

it "returns nil when there's no super method in the parent" do
method = Object.new.method(:method)
method.super_method.should == nil
end

it "returns nil when the parent's method is removed" do
object = MethodSpecs::B.new
method = object.method(:overridden)

MethodSpecs::A.class_eval { undef :overridden }

method.super_method.should == nil
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/unboundmethod/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ class A
def baz(a, b)
return [__FILE__, self.class]
end
def overriden; end
def overridden; end
end

class B < A
14 changes: 14 additions & 0 deletions spec/ruby/core/unboundmethod/super_method_spec.rb
Original file line number Diff line number Diff line change
@@ -9,4 +9,18 @@
meth = meth.super_method
meth.should == UnboundMethodSpecs::A.instance_method(:overridden)
end

it "returns nil when there's no super method in the parent" do
method = Object.instance_method(:method)
method.super_method.should == nil
end

it "returns nil when the parent's method is removed" do
object = UnboundMethodSpecs::B
method = object.instance_method(:overridden)

UnboundMethodSpecs::A.class_eval { undef :overridden }

method.super_method.should == nil
end
end
1 change: 0 additions & 1 deletion spec/tags/ruby/core/method/super_method_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/unboundmethod/super_method_tags.txt

This file was deleted.