From: Nathan Date: 2008-03-10T08:21:47+09:00 Subject: Re: passing procs around in variables Thanks, that's great. On Mar 9, 11:02 pm, "Stefan Lang" wrote: > 2008/3/9, Nathan : > > > > > [...] > > Now, the Item class, which each menu item is an object of, doesn't > > work as expected... take a look here:http://pastie.caboo.se/163781. > > When I try to call myItem.execute!, it complains "no block given". If > > I call myItem.execute! { 2 + 1}, then it works, but that's not what I > > want... > > class Item > > attr_reader :text > > > def initialize(description, &proc) > > @description = description > > @proc = proc > > end > > > def execute! > > yield @proc > > end > > end > > Use yield when the block is _not_ stored in a variable. > What your yield line does is this: Call the block given to > execute! with @proc as argument. > > Once you have a proc object, you can call it, well, with > the "call" method. Just change "yield @proc" to > "@proc.call" and it should work. > > HTH, > Stefan