Project

General

Profile

Actions

Bug #3562

closed

regression in respond_to?

Added by tenderlovemaking (Aaron Patterson) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3dev (2010-07-12 trunk 28620) [x86_64-darwin10.3.1]
Backport:
[ruby-core:31217]

Description

=begin
respond_to? returns false for protected methods. This breaks classes that want to inflect on themselves. For example:

 class Foo
   protected
   def do_bar
     "bar"
   end
 
   def method_missing name
     super unless respond_to?(:"do_#{name}")
     send(:"do_#{name}")
   end
 end
 
 class Subclass < Foo
   protected
   def do_baz
     "baz"
   end
 end
 
 p Foo.new.bar
 p Subclass.new.baz

This code works in 1.8, 1.9.2, but not trunk. This change to respond_to?() breaks existing ruby code[1]. Is that intended? Could we compromise by including private and protected methods when an object inflects upon itself?

  1. http://github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/base.rb#L203
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0