From: "Sandor Szücs" Date: 2013-01-05T19:45:58+09:00 Subject: Re: respond_to_missing? On 1/4/13 3:14 AM, Intransition wrote: > Can anyone explain `#respond_to_missing?`. > The answer can be found at [1]. irb:0> class Bar irb:1> def method_missing name, *args irb:2> p args irb:2> end irb:1> irb:1* def respond_to? name, include_private = false irb:2> true irb:2> end irb:1> end => nil irb:0> Bar.new.respond_to? :does_not_exist => true irb:0> Bar.new.method :does_not_exist NameError: undefined method `does_not_exist' for class `Bar' from (irb):112:in `method' from (irb):112 from /Users/sz/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in `
' irb:0> class Foo irb:1> def respond_to? *args; super; end irb:1> irb:1* def respond_to_missing? *args irb:2> true irb:2> end irb:1> end => nil irb:0> Foo.new.respond_to? :does_not_exist => true irb:0> Foo.new.method :does_not_exist => # [1] http://stackoverflow.com/questions/13793060/respond-to-vs-respond-to-missing -- All the best, Sandor Szücs