Skip to content

Commit

Permalink
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1807,11 +1807,15 @@ public IRubyObject newMethod(IRubyObject receiver, final String methodName, bool

@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY)
public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) {
Visibility visibility = context.getCurrentVisibility();
return defineMethodFromBlock(context, arg0, block, visibility);
}

public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0, Block block, Visibility visibility) {
final Ruby runtime = context.runtime;
RubySymbol nameSym = TypeConverter.checkID(arg0);
String name = nameSym.toString();
DynamicMethod newMethod;
Visibility visibility = PUBLIC;

if (!block.isGiven()) {
throw runtime.newArgumentError("tried to create Proc object without a block");
@@ -1848,11 +1852,15 @@ public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block

@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY)
public IRubyObject define_method(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
Visibility visibility = context.getCurrentVisibility();
return defineMethodFromCallable(context, arg0, arg1, visibility);
}

public IRubyObject defineMethodFromCallable(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Visibility visibility) {
final Ruby runtime = context.runtime;
RubySymbol nameSym = TypeConverter.checkID(arg0);
String name = nameSym.toString();
DynamicMethod newMethod;
Visibility visibility = PUBLIC;

if (runtime.getProc().isInstance(arg1)) {
// double-testing args.length here, but it avoids duplicating the proc-setup code in two places
@@ -1873,6 +1881,7 @@ public IRubyObject define_method(ThreadContext context, IRubyObject arg0, IRubyO

return nameSym;
}

@Deprecated
public IRubyObject define_method(ThreadContext context, IRubyObject[] args, Block block) {
switch (args.length) {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/TopSelfFactory.java
Original file line number Diff line number Diff line change
@@ -95,13 +95,13 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
if (klass == singletonClass) warnWrapper(context);
return klass.define_method(context, arg0, block);
return klass.defineMethodFromBlock(context, arg0, block, Visibility.PUBLIC);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
if (klass == singletonClass) warnWrapper(context);
return klass.define_method(context, arg0, arg1, block);
return klass.defineMethodFromCallable(context, arg0, arg1, Visibility.PUBLIC);
}
});

0 comments on commit 6ed2276

Please sign in to comment.