Skip to content

Commit

Permalink
Attempt to emulate MRI rules for when to use the frame's visbility
Browse files Browse the repository at this point in the history
The rules are spelled out in a comment and abbreviated here:

* Paths expanded by the system, like ~, get 'filesystem' encoding
* Calls given a relative dir use that string's encoding
* Otherwise, use input string's encoding.

This improves specs by removing one tag, and passes three new
specs. We still have a couple outstanding tags here, though.

Fixes #3854.
headius committed May 11, 2016
1 parent 8f0e2c0 commit 9255a39
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1868,10 +1868,19 @@ 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();
Visibility visibility = getVisibilityForDefineMethod(context);

return defineMethodFromBlock(context, arg0, block, visibility);
}

private Visibility getVisibilityForDefineMethod(ThreadContext context) {
Visibility visibility = PUBLIC;

// These checks are similar to rb_vm_cref_in_context from MRI.
if (context.getCurrentFrame().getSelf() == this) visibility = context.getCurrentVisibility();
return visibility;
}

public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0, Block block, Visibility visibility) {
final Ruby runtime = context.runtime;
RubySymbol nameSym = TypeConverter.checkID(arg0);
@@ -1913,7 +1922,8 @@ public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0

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

return defineMethodFromCallable(context, arg0, arg1, visibility);
}

0 comments on commit 9255a39

Please sign in to comment.