On May 21, 6:10 pm, Robert Klemme <shortcut... / googlemail.com> wrote: > On 21.05.2007 19:52, Trans wrote: > > > > > > > On May 21, 11:55 am, Robert Klemme <shortcut... / googlemail.com> wrote: > >> On 21.05.2007 17:51, Trans wrote: > > >>> On May 21, 10:35 am, Robert Klemme <shortcut... / googlemail.com> wrote: > >>>>> An alternative is to use a functor (a function delegator) for your > >>>>> parameters, eg. > >>>>> f = Foo.new > >>>>> f.range(1,5).each{|x| p x} > >>>> ... which is basically the same as using to_enum - only less portable; > >>>> to_enum works with *all* methods. :-) > >>> That true. But at least it reads much better. > >> Even that is subjective: I personally prefer to read f.to_enum(:range, > >> 1, 5) because then I know this is going to be capable of all the > >> Enumerable methods. YMMD though. :-) > > > Not sure I understand what you mean by "because then I know this is > > going to be capable of all the Enumerable methods", b/c what #range > > returns can be too. > > Yes, it *can* - that's not the point. But if I see foo.to_enum(:bar, > 24, 5) in code I know already that the return value of #to_enum includes > Enumerable while in the case of #range I have to look into documentation. > > > In fact I think it can be defined like this: > > > def range(x,y) > > Functor.new(self) do |op, obj| > > obj.to_enum(op,x,y) > > end > > end > > > (don't quote me on that though, I haven't tested it.) > > :-) > > > So I take it you actually mean that using to_enum is better in that > > you don't need to know anything about #range to understand the code? > > Exactly. > > > I can understand, but I think its preferable to break things down into > > smaller, more readable, sub-functions. > > Um, I am not sure I understand what you mean by this in the current > context. Can you please elaborate? Hmmm... The best answer I can probably give is actually this: http://thinking-forth.sourceforge.net/ Sorry it's not a concise answer, but this conversation could very well EXPLODE from here. And I'd prefer to keep DRY ;-) T.