From: Ross Bamford Date: 2005-12-02T17:42:34+09:00 Subject: Re: require! On Fri, 02 Dec 2005 06:13:38 -0000, Hal Fulton wrote: > James Edward Gray II wrote: >> On Nov 30, 2005, at 7:52 PM, Ross Bamford wrote: >> >>> On another note, though, I also found out that calling amethod (*args) >>> works with anything with 'each' (any Enumerable?), which made me >>> smile. It was the post about ranges that made me get that :) >> Actually * looks for a to_a. > > I always thought it looked for to_ary... now someone says it looks > first for to_ary, then to_a. > > And I had no idea that it would work with just #each defined. > When I kicked this thread off, I'd just done some quick tests that suggested it worked like above, and on anything with each, and I guessed that (since Enumerable defines to_a, and everything is in terms of each) that it must work that way. I'm still pretty sure it does to_ary followed by to_a, but as others showed me, it doesn't actually work with just 'each'. class Clazz def each yield 1 yield 2 yield 3 end end c = Clazz.new c = [*c] p c => [#] That's I think coming from the default to_a, and with the 1.9 snapshot I have it gives a TypeError ('Cannot convert Clazz into Array' - the default to_a is gone). It does _seem_ to work on anything with each if you include Enumerable, but that's because Enumerable defines everything (including to_a) in terms of 'each'. If you add 'include Enumerable' to the class definition above, you get [1,2,3] as expected. -- Ross Bamford - rosco@roscopeco.remove.co.uk "\e[1;31mL"