Skip to content

Commit

Permalink
Set original Module to definedClass of methods
Browse files Browse the repository at this point in the history
Set original Module to definedClass of methods when
new methods are defined to PrependedModule.

Before this commit, definedClass of method a
is class c but definedClass of method b
is PrependedModule:

```
M = Module.new
c = Class.new {
  def a; end
  prepend M
  def b; end
}
```

This commit will set definedClass of method b
to class c and fix `TestMethod#test_alias_owner`.

Signed-off-by: Charles Oliver Nutter <headius@headius.com>
yui-knk authored and headius committed Jan 8, 2018
1 parent e6a8b40 commit ce434ec
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/PrependedModule.java
Original file line number Diff line number Diff line change
@@ -53,6 +53,12 @@ public PrependedModule(Ruby runtime, RubyClass superClass, RubyModule origin) {
}
}

@Override
public void addMethod(String name, DynamicMethod method) {
super.addMethod(name, method);
method.setDefinedClass(origin);
}

@Override
public boolean isPrepended() {
return true;
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1178,6 +1178,11 @@ public IRubyObject singleton_class_p(ThreadContext context) {
public void addMethod(String name, DynamicMethod method) {
testFrozen("class/module");

if (methodLocation != this) {
methodLocation.addMethod(name, method);
return;
}

if (this instanceof MetaClass) {
// FIXME: Gross and not quite right. See MRI's rb_frozen_class_p logic
RubyBasicObject attached = (RubyBasicObject)((MetaClass)this).getAttached();
1 change: 0 additions & 1 deletion test/mri/excludes/TestMethod.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
exclude :test___dir__, "needs investigation"
exclude :test_alias_owner, "needs investigation"
exclude :test_body, "fails due RubyVM constant"
exclude :test_callee, "needs investigation"
exclude :test_clone, "needs investigation"

0 comments on commit ce434ec

Please sign in to comment.