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: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c67f1b4f877d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f2b3a171e6e3
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 26, 2016

  1. Copy the full SHA
    9c49a58 View commit details

Commits on Oct 30, 2016

  1. Merge pull request #4250 from headius/methods_have_owners

    Prepend must set method's "defined class" to the new bottom.
    headius authored Oct 30, 2016
    Copy the full SHA
    f2b3a17 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/AbstractRubyMethod.java
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public String getMethodName() {

@JRubyMethod(name = "owner")
public IRubyObject owner(ThreadContext context) {
return implementationModule;
return method.getDefinedClass();
}

@JRubyMethod(name = "source_location")
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/PrependedModule.java
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ public PrependedModule(Ruby runtime, RubyClass superClass, RubyModule origin) {
for (Map.Entry<String, DynamicMethod> entry : methods.entrySet()) {
DynamicMethod method = entry.getValue();
method.setImplementationClass(this);
method.setDefinedClass(origin);
}
}

7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1886,10 +1886,10 @@ public IRubyObject newMethod(IRubyObject receiver, final String methodName, bool
}
}

RubyModule implementationModule = method.getImplementationClass();
RubyModule implementationModule = method.getDefinedClass();
RubyModule originModule = this;
while (originModule != implementationModule && originModule.isSingleton()) {
originModule = ((MetaClass)originModule).getRealClass();
while (originModule != implementationModule && (originModule.isSingleton() || originModule.isIncluded())) {
originModule = originModule.getSuperClass();
}

AbstractRubyMethod newMethod;
@@ -2963,7 +2963,6 @@ private void doIncludeModule(RubyModule baseModule) {
private void doPrependModule(RubyModule baseModule) {
List<RubyModule> modulesToInclude = gatherModules(baseModule);

RubyClass insertBelowSuperClass = null;
if (methodLocation == this) {
// In the current logic, if we getService here we know that module is not an
// IncludedModule, so there's no need to fish out the delegate. But just
Original file line number Diff line number Diff line change
@@ -51,10 +51,12 @@
* delegation or callback mechanisms.
*/
public abstract class DynamicMethod {
/** The Ruby module or class in which this method is immediately defined. */
/** The Ruby module or class from which this method should `super`. Referred to as the `owner` in C Ruby. */
protected RubyModule implementationClass;
/** The "protected class" used for calculating protected access. */
protected RubyModule protectedClass;
/** The module or class that originally defined this method. Referred to as the `defined_class` in C Ruby. */
protected RubyModule definedClass;
/** The visibility of this method. This is the ordinal of the Visibility enum value. */
private byte visibility;
/** The serial number for this method object, to globally identify it */
@@ -316,6 +318,24 @@ public void setImplementationClass(RubyModule implClass) {
protectedClass = calculateProtectedClass(implClass);
}

/**
* Get the original owner of this method/
*/
public RubyModule getDefinedClass() {
RubyModule definedClass = this.definedClass;

if (definedClass != null) return definedClass;

return implementationClass;
}

/**
* Set the defining class for this method, as when restructuring hierarchy for prepend.
*/
public void setDefinedClass(RubyModule definedClass) {
this.definedClass = definedClass;
}

/**
* Get the visibility of this method.
*