? Ruby considering ? and ! as valid characters in a method name. respond_to and respond_to? are different. ? indicates that this should be true or false (by agreement, this is not a requirement). In particular:
respond_to? is a Ruby method for determining whether a class has a specific method on it. For example,
@user.respond_to?('eat_food')
will return true if the User class has a eat_food method on it.
respond_to is a Rails method for responding to specific types of requests. For example:
def index @people = Person.find(:all) respond_to do |format| format.html format.xml { render :xml => @people.to_xml } end end
However, in the RailsTutorial link below, you see the RSpec should method, which interacts with the RSpec respond_to method. This will not be available on the console unless you run the rails console test .
Tim Sullivan Jul 27 '11 at 19:09 2011-07-27 19:09
source share