From: Devin Mullins Date: 2005-09-27T21:14:33+09:00 Subject: Re: How each class splats Robert Klemme wrote: >Devin Mullins wrote: > > >>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? > > Mrh? ArrayOfB#each does the trick. You understand DelegateClass, no? (Probably much better than I do...) >>>a.kind_of? Array >>> >>> >=> false > > >Hm... > > Yes, that's the downside, but it's not necessarily much of one, is it? Devin