# Strange SimpleDelegator behaviour regarding blocks

**URL:** <https://www.ruby-forum.com/t/strange-simpledelegator-behaviour-regarding-blocks/173810>\
**Category:** Ruby\
**Created:** [August 15, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/strange-simpledelegator-behaviour-regarding-blocks/173810 "2009-08-15T13:49:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fstroehle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/8797f3/32.png) [@fstroehle](https://www.ruby-forum.com/u/fstroehle)\
**Post date:** [August 15, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/strange-simpledelegator-behaviour-regarding-blocks/173810/1 "2009-08-15T13:49:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![fstroehle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/8797f3/32.png) [@fstroehle](https://www.ruby-forum.com/u/fstroehle)\
**Post date:** [August 16, 2009, 10:31am UTC](https://www.ruby-forum.com/t/strange-simpledelegator-behaviour-regarding-blocks/173810/2 "2009-08-16T10:31:11Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fstroehle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/8797f3/32.png) [@fstroehle](https://www.ruby-forum.com/u/fstroehle)\
**Post date:** [August 15, 2009, 3:29pm UTC](https://www.ruby-forum.com/t/strange-simpledelegator-behaviour-regarding-blocks/173810/3 "2009-08-15T15:29:52Z")

</div>

On Sat, Aug 15, 2009 at 7:48 PM, Fabian  
Streitel[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
