From: Robert Klemme Date: 2009-10-09T05:40:11+09:00 Subject: Re: Mixing instance_eval and block with arguments On 10/08/2009 09:21 PM, Tony Arcieri wrote: > [Note: parts of this message were removed to make it a legal post.] > > On Thu, Oct 8, 2009 at 10:04 AM, Robert Klemme > wrote: > >> In other words: I like to define a block as an initializer which I can >> store away somewhere and invoke that initializer later on in the >> context of "self" and pass arguments at the same time. Any ideas how >> I can accomplish this elegantly? >> > > Sounds like you need instance_exec, which is a 1.9 feature but there are > implementations for 1.8: > > http://eigenclass.org/hiki.rb?instance_exec 1.9 is OK. irb(main):001:0> l = lambda {|a| self + a} => # irb(main):002:0> 1.instance_exec(2,&l) => 3 Perfect! This is _exactly_ what I need. Thanks a bunch! This article is so old, I can't believe I missed this completely. Amazing: learn something new every day. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/