From: "David A. Black" Date: 2004-07-08T19:53:58+09:00 Subject: Re: Array::index and rindex operator Hi -- On Thu, 8 Jul 2004, George Ogata wrote: > "David A. Black" writes: > > > On Wed, 7 Jul 2004, George Ogata wrote: > > So since the interpreter can't figure it out on it's own, you'd need > to give it a kick by providing some syntactic signal, e.g.: > > def x & # the '&' means "I can take a block" > ## ... maybe yield ... > end > > ....but then ruby has a > > >> "no declarations" philosophy (i.e., no declaring "I take blocks" in > >> the method definition). > > So in the end all I'm saying is that in an Ideal Magical World of > Happiness (TM), I think it should complain, but I understand that it's > not really practical now. You could come fairly close with something like: class NoBlockError < Exception; end module Kernel def b! raise unless block_given? end end class C def initialize(x) b! @x = yield(x) * 10 end end except it reports the error as from the line in #b! (isn't there some way around that? I can't remember). > >> As for the "left-to-right" view, there's no precedence for this being > >> silently ignored in the presence of ambiguity, is there? > > > > I don't think any existing methods do this; I'm really just > > speculating about whether or not it would make sense to write a method > > that way. I think it would, at an abstract level, but having the > > method intervene if one calls it ambiguously also makes sense, perhaps > > more sense at the practical level. > > Hmm, it'd be interesting to see. It would be a question of something like: def m(*args) if args.empty? # do block-aware version else # use args end end David -- David A. Black dblack@wobblini.net