From 130539702fdac0e396a726a3b4e2194eed7fbab2 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 19 Jan 2024 14:34:15 -0600 Subject: [PATCH] Factor out a few more method hooks 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. --- core/src/main/java/org/jruby/RubyModule.java | 30 +++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index 005af6f9e0b..550224ff56c 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -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?") @@ -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) { @@ -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 * */