Devin Mullins wrote:
> 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.

Can't be:

>> class Foo
>> def each() yield 1; yield 2 end
>> end
=> nil
>> a=[Foo.new, Foo.new]
=> [#<Foo:0x1018b6c0>, #<Foo:0x1018b6a8>]
>> a.each {|x,y| puts x,y}
#<Foo:0x1018b6c0>
nil
#<Foo:0x1018b6a8>
nil
=> [#<Foo:0x1018b6c0>, #<Foo:0x1018b6a8>]

It must be something different.

Ah!  I remember: it's #to_ary:

>> class Bar
>> def to_ary() [1,2] end
>> end
=> nil
>> a=[Bar.new, Bar.new]
=> [#<Bar:0x101c5f50>, #<Bar:0x101c5f38>]
>> a.each {|x,y| puts x,y}
1
2
1
2
=> [#<Bar:0x101c5f50>, #<Bar:0x101c5f38>]

I *knew* it had to be something simple.  So Trans, that's the solution!

> You understand DelegateClass, no?
> (Probably much better than I do...)

I know and understand it.  I dunno whether better or worse than you. :-)

Kind regards

    robert