diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index 2d71ff8dea6..005af6f9e0b 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -2289,11 +2289,19 @@ private void addAccessor(ThreadContext context, RubySymbol identifier, Visibilit final String variableName = identifier.asInstanceVariable().idString(); if (readable) { addMethod(internedIdentifier, new AttrReaderMethod(methodLocation, visibility, variableName)); - callMethod(context, "method_added", identifier); + methodAdded(context, identifier); } if (writeable) { identifier = identifier.asWriter(); addMethod(identifier.idString(), new AttrWriterMethod(methodLocation, visibility, variableName)); + methodAdded(context, identifier); + } + } + + protected void methodAdded(ThreadContext context, RubySymbol identifier) { + if (isSingleton()) { + ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", identifier); + } else { callMethod(context, "method_added", identifier); } } @@ -3491,7 +3499,7 @@ public IRubyObject _module_function(ThreadContext context, IRubyObject[] args) { newMethod.setImplementationClass(getSingletonClass()); newMethod.setVisibility(PUBLIC); getSingletonClass().addMethod(name.idString(), newMethod); - callMethod(context, "singleton_method_added", name); + getSingletonClass().methodAdded(context, name); } } @@ -3619,11 +3627,7 @@ public IRubyObject aliasMethod(ThreadContext context, IRubyObject newId, IRubyOb defineAlias(newSym.idString(), oldSym.idString()); - if (isSingleton()) { - ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym); - } else { - callMethod(context, "method_added", newSym); - } + methodAdded(context, newSym); return newSym; }