Strange SimpleDelegator behaviour regarding blocks

Hey folks, just stumbled across a little problem:

001:0> a = SimpleDelegator.new([])
=> []
002:0> a << 12 << 13
=> [12, 13]
003:0> a.each do puts 1 end # (1)
1
1
004:0> class Array
005:1> def foo
006:2> yield
007:2> end
008:1> end
009:0> a.foo do p 1 end # (2)
LocalJumpError: no block given
from (irb):6:in foo' from /usr/lib/ruby/1.8/delegate.rb:159:insend
from /usr/lib/ruby/1.8/delegate.rb:159:in method_missing' from (irb):9 from :0 010:0> Array.new.foo do p 1 end 1 011:0> a.__setobj__(Array.new) => [] 013:0> a.foo do p 1 end # (3) LocalJumpError: no block given from (irb):6:infoo’
from /usr/lib/ruby/1.8/delegate.rb:159:in __send__' from /usr/lib/ruby/1.8/delegate.rb:159:inmethod_missing’
from (irb):13
from :0

As you can see, the blocks given to the methods are not passed along by
the
delegator to
the actual delegatee in (2) and (3)… but only for methods added later
on,
the original
methods get it, as in (1)…
Am I missing something or is this a bug? In the very least it violates
the
Principle of Least
Surprise and kept me on a goose chase for the last 2 days.

Greetz!

ah, so it’s a bug then, I guess… and they seem to know about it.
Then I guess, I don’t have to file an error report…

2009/8/15 botp [email protected]

On Sat, Aug 15, 2009 at 7:48 PM, Fabian
Streitel[email protected] wrote:

Hey folks, just stumbled across a little problem:

009:0> a.foo do p 1 end # (2)
LocalJumpError: no block given

just a note: this works on ruby1.9

kind regards -botp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs