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