Using the missing method

suggest change
class Animal
  def method_missing(method, *args, &block)
    say, speak = method.to_s.split("_")
    if say == "say"
      speak
    else
      super
    end
  end
end

# => a = Animal.new
# => a.say_moo
# => "moo"
# => a.shout_moo
# => NoMethodError: undefined method 'shout_moo' for an instance of Animal

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents