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
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyUnboundMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ public IRubyObject bind_call(ThreadContext context, IRubyObject[] args, Block bl
IRubyObject[] newArgs = new IRubyObject[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, args.length - 1);

receiver.getMetaClass().checkValidBindTargetFrom(context, (RubyModule) owner(context), true);
RubyClass receiverClass = receiver.getMetaClass();

return method.call(context, receiver, implementationModule, methodName, newArgs, block);
receiverClass.checkValidBindTargetFrom(context, (RubyModule) owner(context), true);

CacheEntry methodEntry = convertUnboundMethodToCallableEntry(context, receiverClass);

return method.call(context, receiver, methodEntry.sourceModule, methodName, newArgs, block);
}

@JRubyMethod(name = {"inspect", "to_s"})
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/unboundmethod/bind_call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
@child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
@child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
@normal_um_super = UnboundMethodSpecs::Mod.instance_method(:foo_super)
@parent_um_super = UnboundMethodSpecs::Parent.new.method(:foo_super).unbind
end

it "raises TypeError if object is not kind_of? the Module the method defined in" do
Expand Down Expand Up @@ -47,4 +49,10 @@ def singleton_method
um = p.method(:singleton_method).unbind
->{ um.bind_call(other) }.should raise_error(TypeError)
end

it "allows calling super for module methods bound to hierarchies that do not already have that module" do
p = UnboundMethodSpecs::Parent.new

@normal_um_super.bind_call(p).should == true
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/unboundmethod/bind_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
@child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
@child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
@normal_um_super = UnboundMethodSpecs::Mod.instance_method(:foo_super)
@parent_um_super = UnboundMethodSpecs::Parent.new.method(:foo_super).unbind
end

it "raises TypeError if object is not kind_of? the Module the method defined in" do
Expand Down Expand Up @@ -58,4 +60,10 @@ def singleton_method
um = p.method(:singleton_method).unbind
->{ um.bind(other) }.should raise_error(TypeError)
end

it "allows calling super for module methods bound to hierarchies that do not already have that module" do
p = UnboundMethodSpecs::Parent.new

@normal_um_super.bind(p).call.should == true
end
end
4 changes: 4 additions & 0 deletions spec/ruby/core/unboundmethod/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def original

module Mod
def from_mod; end
def foo_super; super; end
end

class Methods
Expand Down Expand Up @@ -63,6 +64,9 @@ def my_private_method; end

class Parent
def foo; end
def foo_super
true
end
def self.class_method
"I am #{name}"
end
Expand Down