Skip to content

Commit fde405b

Browse files
authored
Merge pull request jruby#9280 from headius/respond_to_missing_missing
Check if respond_to_missing? exists before respond_to?
2 parents 0fd67cc + 55ff55c commit fde405b

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

core/src/main/java/org/jruby/RubyBasicObject.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,9 +2225,22 @@ final RubyBoolean respond_to_p(ThreadContext context, IRubyObject methodName, fi
22252225

22262226
if (getMetaClass().respondsToMethod(name.idString(), !includePrivate, context.getCurrentStaticScope())) return context.tru;
22272227

2228-
Ruby runtime = context.runtime;
2229-
IRubyObject result = sites(context).respond_to_missing.call(context, this, this, name, runtime.newBoolean(includePrivate));
2230-
return context.runtime.newBoolean(result.isTrue());
2228+
IRubyObject respondToMissing = basicObjectRespondToMissing(context, getMetaClass(), this, name, includePrivate);
2229+
if (respondToMissing == UNDEF) return context.fals;
2230+
return asBoolean(context, respondToMissing.isTrue());
2231+
}
2232+
2233+
// MRI: basic_obj_respond_to_missing, sort of
2234+
private IRubyObject basicObjectRespondToMissing(ThreadContext context, RubyClass klass, IRubyObject obj,
2235+
IRubyObject mid, boolean includePrivate)
2236+
{
2237+
CacheEntry entry = sites(context).respond_to_missing.retrieveCache(this);
2238+
2239+
if (!entry.method.isUndefined()) {
2240+
return entry.method.call(context, this, klass, "respond_to_missing?", mid, asBoolean(context, includePrivate));
2241+
}
2242+
2243+
return UNDEF;
22312244
}
22322245

22332246
/**

core/src/main/java/org/jruby/runtime/JavaSites.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class JavaSites {
6161

6262
public static class BasicObjectSites {
6363
public final CallSite respond_to = new FunctionalCachingCallSite("respond_to?");
64-
public final CallSite respond_to_missing = new FunctionalCachingCallSite("respond_to_missing?");
64+
public final CachingCallSite respond_to_missing = new FunctionalCachingCallSite("respond_to_missing?");
6565
public final CallSite initialize_dup = new FunctionalCachingCallSite("initialize_dup");
6666
public final CallSite initialize_clone = new FunctionalCachingCallSite("initialize_clone");
6767
public final CallSite to_s = new FunctionalCachingCallSite("to_s");

0 commit comments

Comments
 (0)