From: Mike Harris Date: 2006-11-30T06:42:05+09:00 Subject: Re: returning Procs from methods? Giles Bowkett wrote: > I've got something which basically does this: > > some_string.scan(/(whatever)/).each &do_stuff > > where &do_stuff is a Proc. > > currently there's a case/when that assigns different Procs to do_stuff > depending on the value of some_string. > > what I want to do is something like this: > > some_string.scan(/(whatever)/).each do_stuff > > where do_stuff() is a method which figures out what Proc to return to > the each(). > > however, I can't seem to build a method which returns a Proc. > > can it be done? > The foo method returns the proc def foo lambda { |x| x + 2 } end foo.call(4) #6 def other_foo(&b) b end var = other_foo { |x| x + 2 } var.call(4) #6