From: "trans. (T. Onoma)" Date: 2005-01-14T00:07:49+09:00 Subject: Re: Duck Typing as Pattern Matching I haven't read the entire thread so forgive me if I'm rehashing.... On Thursday 13 January 2005 09:51 am, itsme213 wrote: | "ts" wrote in message | | > p txn.respond_to?(:create_modify) | > p txn.create_modify | | Oh oh, even more Ruby experts join the chorus ? :-) | | My claim is this: If you redefine #method_missing so your object handles | x.foo as the caller would expect, then you _should_ define | x.respond_to?(:foo) to return true. I do not claim that Ruby should | prohibit code that does not do this. I wonder if method missing would be better if these two "tiers" were built in to it. This would require dual "blocks" so I'm not sure how to notate it but: def method_missing(meth, *args) upon meth == :create_modify # do whatever upon ... # ... end Then #respond_to? can utilize the "upon" block to determine responses correctly. | I am interested in your thoughts on this claim. | | p.s. I know it is possible to redefine #send so that x.send :foo works, but | x.foo does not. I think this a practice to be actively discouraged. But | let's leave that out for now. Redefining #send is a very bad idea. IMHO That's one of those methods I think should be off limits and return an error if you try to redefine it. T.