From: "trans. (T. Onoma)" Date: 2005-01-14T05:43:25+09:00 Subject: Re: Duck Typing as Pattern Matching On Thursday 13 January 2005 01:34 pm, E S wrote: | > L辰hett辰j辰: "trans. (T. Onoma)" | > Aihe: 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. | | Are you thinking something different than | | def method_missing(meth, *args) | case meth | when :create_modify | # ... | end | end | Yes. A bit different on two accounts. 1) The "upon" clause is just a regular boolean returning block, like #if, not divided and limited to matching like #case is. And 2) it would be instrumental to how #method_missing works, thus in some manner queryable, so that #respond_to? and potentially other methods could make use of it. That's the idea any way. There may very well be a better way to achieve the same goal. T.