From: Marc-Andre Lafortune Date: 2010-07-07T02:31:28+09:00 Subject: [ruby-dev:41837] Re: respond_to?() returns true Hi, On Tue, Jul 6, 2010 at 1:23 AM, Yukihiro Matsumoto wrote: > It's accepted. Great. > Some RubySpec test failures are caused by this > change.  We should fix them after the change is checked in.  Will you? Yes (done for the most part). Looking more closely at the change, it is not what I expected. class C protected def is_protected; end end C.new.respond_to?(:is_protected, true) # => false, I expected true I feel that either `C.new.respond_to?(:is_protected, true)` should return true, or else there should be another way to ask if a method respond_to a protected method, say like `C.new.respond_to?(:is_protected, :any)` Here's a patch for the first option. diff --git a/vm_method.c b/vm_method.c index becce27..ea4afe4 100644 --- a/vm_method.c +++ b/vm_method.c @@ -566,8 +566,9 @@ rb_method_boundp(VALUE klass, ID id, int ex) rb_method_entry_t *me = rb_method_entry(klass, id); if (me != 0) { - if ((ex & NOEX_RESPONDS) && (me->flag & NOEX_PROTECTED) || - (ex & ~NOEX_RESPONDS) && (me->flag & NOEX_PRIVATE)) { + if ((ex & ~NOEX_RESPONDS) && ( + (me->flag & NOEX_PRIVATE) || + ((ex & NOEX_RESPONDS) && (me->flag & NOEX_PROTECTED)))) { return 0; } if (!me->def) return 0; @@ -1257,10 +1258,10 @@ rb_respond_to(VALUE obj, ID id) /* * call-seq: - * obj.respond_to?(symbol, include_private=false) -> true or false + * obj.respond_to?(symbol, include_all=false) -> true or false * * Returns +true+ if _obj_ responds to the given - * method. Private methods are included in the search only if the + * method. Private and protected methods are included in the search only if the * optional second parameter evaluates to +true+. * * If the method is not implemented, @@ -1286,7 +1287,7 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj) /* * call-seq: - * obj.respond_to_missing?(symbol, include_private) -> true or false + * obj.respond_to_missing?(symbol, include_all) -> true or false * * Hook method to return whether the _obj_ can respond to _id_ method * or not.