From: Jeffrey Moss Date: 2005-07-29T04:15:22+09:00 Subject: Re: method_missing crazyness I think optional type checking, key word being optional, would actually compliment the duck typing, the method with no type(s) in the argument list would become the default. Adding a type would only make it more specific, a shortcutted form of "return custom_string_method if param.is_a?(String)". It would come in handy more in the complex class structures than the simple "method_missing" case. In the case of the complex class structure, instead of being a substitute for the switch or conditional statement in method_missing, it would be a substitute for this: def custom_string_method(obj) # do custom stuff on a string end def custom_method(obj) next_method_name = "custom_#{obj.class.to_s.downcase}_method" if self.respond_to?(next_method_name) return self.send(next_method_name, obj) end # do default custom stuff end Which would allow you to override methods for certain objects without overriding custom_method and adding new conditionals. If you weren't using method overrides, it would only be syntactical sugar, but in this case it actually cleans up the app a bit to say: def custom_method(String obj) # do custom stuff on a string end def custom_method(obj) # do default custom stuff end -Jeff ----- Original Message ----- From: "Dave Fayram" To: "ruby-talk ML" Sent: Thursday, July 28, 2005 12:16 PM Subject: Re: method_missing crazyness On 7/28/05, Jeffrey Moss wrote: > Multimethods with optional typed argument lists would be totally awesome. > It > wouldn't break backward compatibility either. Wasn't that the most popular > requested feature for ruby 2? Aren't these against the spirit of duck typing, though? I thought that Ruby was moving away from needing type-checking dispatch rather than towards needing it. The only time I've ever needed it is when I was doing some heavy math code. When your set of types is small and well known, it is much more elegant than loading up on the to_somethings or making a kind_of? if statement clause. > > As for the method_missing trick, I think it is too much of a special case, > because what if you want to use a custom prefix instead? > I would venture to say special prefixes or suffixes are actually the common case. -- -- Dave Fayram (II) dfayram@gmail.com