Skip to content

Commit

Permalink
Factor out a few more method hooks
Browse files Browse the repository at this point in the history
These are only called in one place, but may be needed in the
future if they should be called for other logic that undefines or
removes methods.
  • Loading branch information
headius committed Jan 19, 2024
1 parent 1008344 commit 1305397
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1444,11 +1444,9 @@ public void undef(ThreadContext context, String name) {
}
methodLocation.addMethod(name, UndefinedMethod.getInstance());

if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_undefined", runtime.newSymbol(name));
} else {
callMethod(context, "method_undefined", runtime.newSymbol(name));
}
RubySymbol nameSymbol = runtime.newSymbol(name);

methodUndefined(context, nameSymbol);
}

@JRubyMethod(name = "include?")
Expand Down Expand Up @@ -1567,11 +1565,7 @@ public void removeMethod(ThreadContext context, String id) {
invalidateCacheDescendants();
}

if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_removed", name);
} else {
callMethod(context, "method_removed", name);
}
methodRemoved(context, name);
}

private static void warnMethodRemoval(final ThreadContext context, final String id) {
Expand Down Expand Up @@ -2306,6 +2300,22 @@ protected void methodAdded(ThreadContext context, RubySymbol identifier) {
}
}

private void methodUndefined(ThreadContext context, RubySymbol nameSymbol) {
if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_undefined", nameSymbol);
} else {
callMethod(context, "method_undefined", nameSymbol);
}
}

private void methodRemoved(ThreadContext context, RubySymbol name) {
if (isSingleton()) {
((MetaClass) this).getAttached().callMethod(context, "singleton_method_removed", name);
} else {
callMethod(context, "method_removed", name);
}
}

/** set_method_visibility
*
*/
Expand Down

0 comments on commit 1305397

Please sign in to comment.