Strange SimpleDelegator behaviour regarding blocks

F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]

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:in `__send__'
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:in `foo'
from /usr/lib/ruby/1.8/delegate.rb:159:in `__send__'
from /usr/lib/ruby/1.8/delegate.rb:159:in `method_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!
 
B

botp

Hey folks, just stumbled across a little problem: ....
009:0> a.foo do p 1 end =A0 # (2)
LocalJumpError: no block given


just a note: this works on ruby1.9

kind regards -botp
 
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top