From: Robert Klemme Date: 2005-09-27T17:56:42+09:00 Subject: Re: How each class splats Devin Mullins wrote: > Robert Klemme wrote: > >> Devin Mullins wrote: >> >> >>> But I think your best bet is define your own Collection object with >>> its own #each. >>> >>> >> I though so, too, but it doesn't help: >> >> >> > Oooh... not what I meant. :) I meant something like this: > > class B > attr_reader :i, :v > def initialize(i,v) > @i, @v = i, v > end > end > > class ArrayOfB < DelegateClass(Array) > def each > super { |b| yield b.i, b.v } > end > end > > a = ArrayOfB.new [B.new(:a, 1), B.new(:b, 2)] > a.each { |i, v| puts "i = #{i.inspect}, v = #{v.inspect}" } Interesting. Why does it work? Which method does the trick here? >> a.class => ArrayOfB >> a.class.ancestors => [ArrayOfB, #, Object, Kernel] >> a.kind_of? Array => false >> Array === a => false Hm... Kind regards robert