[Rails] Method_missing from Ruby for Rails book

Dark Ambient sambient at gmail.com
Sun Jul 30 13:46:21 GMT 2006


I'm having a problem getting this example from the book to work:

class Cookbook
  attr_accessor :title, :author

  def initialize
    @recipes = []
  end

  def method_missing(m, *args, &block)
    @recipes.send(m, *args, &block)
  end
end

cb = Cookbook.new
cb << recipe_for_cake
cb << recipe_for_chicken
beef_dishes = cb.find_all {|recipes| recipe.main_ingredient == "beef" }

I'm getting callable.rb:14: undefined local variable or method
`recipe_for_cake' for main:Object (NameError) so apparently
method_missing is not working.

Stuart


More information about the Rails mailing list