From: Maurice Gladwell Date: 2007-05-30T20:56:08+09:00 Subject: Re: #respond_to? not working for dynamically generated metho David wrote: > [...] > Basically, to know what's going to happen dynamically, you have to run > the program and send the messages. It would be possible to define at writing time the entire range of messages that an object will respond to. Here's how: There are two kinds of messages to which an object responds by something that is not a NoMethodError: 1) Those corresponding to defined instance methods. 2) Those that are handled in some way by method_missing. #1 is already well defined and thus handled by #respond_to?. So if we could just define the range of messages recognized by method_missing, we could have an object return the entire range of messages to which it will respond. Of course, we don't have standard support for that currently, but we could (e.g. with some DSL) declare inside the class definition (e.g. above the `def method_missing`) patterns to which method_missing would respond. So for example, in ActiveRecord::Base we would have something like: responds_to /find_by_.+/ Thus `SomeRailsModel.respond_to? :find_by_name` would have the knowledge it needs to return the correct answer: true. -- M. -- Posted via http://www.ruby-forum.com/.