From: Fabian Streitel Date: 2009-08-15T20:48:54+09:00 Subject: Strange SimpleDelegator behaviour regarding blocks --0015175cdc8a15afdd04712cac60 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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! --0015175cdc8a15afdd04712cac60--