Normally,when ruby is not able to find the method,it usually raises
"NoMethodError: undefined method "methodname"".That's what we always stuck,nothing special.
Above all,because of Ruby is a kind of dynamic language,what it does exactly if it can't find the method is calling "method_missing" method and method_missing raises a NameError exception,what is the point? you're able to apply the method_missing method in your application and do something cool.When we use hash,we normally call hash["key"] or hash[:key].What if we would like to call it something like hash.key.And here is a bit tricky used of it.
def method_missing( id, *args ) if self[id].nil? m = id.to_s if /=$/ =~ m self[m.chomp!] = (args.length < 2 ? args[0] : args) else self[m] end else self[id] end end h = { "foo" => "bar",:blah => "thinkruby"} h.blah # => thinkruby h.foo # => bar
It's not bad,right?

