"David A. Black" <dblack / wobblini.net> schrieb im Newsbeitrag news:Pine.LNX.4.61.0501140520470.15307 / wobblini... > Hi -- > > On Fri, 14 Jan 2005, Robert Klemme wrote: > > >> [I wrote:] > >> > >> There's also the question of the interaction of this with duck typing. > >> Of course that's always a programmer's choice, but I could imagine > >> cases where the caller would expect a duck-typing treatment and not > >> get it. For example: > >> > >> obj = Object.new > >> def obj.times; 10; end > >> str = silly_example("hello", obj) > >> > [...] > > Btw, did you purposely just return an int from your definition of times? > > I mean, no block is invoked from that method. > > I did it wrong. It should be: > > def obj.times(&block) > 10.times &block > end > > >> (Of course you could document your method by saying that it requires > >> an object that responds to to_int, but that seems a bit roundabout > >> compared to just saying you want an object that responds to times.) > > > > It's just another (supposedly shorter) form to write a common idiom. If > > the writer of silly_example decides to do more complex treatment, he can > > still do that. We don't loose anything. Note, that the creator of your > > obj.times() would be similarly surprised if the implementor of > > silly_example had choosen to do it exactly like I presented in the first > > example. > > > > I'm not sure whether I missed your point altogether. Could you please > > elaborate? Thanks! > > Partly I'm just very conservative about special-case syntax and > shortcuts. I can't define exactly why, or exactly where I draw the > line, or whether there's even a line.... I think I'm also not > convinced that this (to_int etc.) is common enough or special enough > to warrant a change in method definitions semantics. I don't think I > can get much more concrete than that, so it may be that at some level > I don't have a point, rather than that you've missed it :-) Ah, ok, I see... :-) Then let's see with what others come up. Maybe I've orverlooked a complete showstopper and we can forget about this immediately. About usage of to_int et al: as these methods are fairly recent (compared to to_i and others) I'd guess that usage is increasing and they might not yet be as prolific as I assumed. Don't have exact numbers though. Thanks for sharing your thoughts! Kind regards robert