how to store a block in a var?

G

Giles Bowkett

Mil perdones, but my brain seems to have gone awol. I have multiple
places in a spec where I need to run the same block of code. I would
be much happier storing this block in a var as a Proc as opposed to
wrapping it up in a method. Is there a way I can do this? My spec
looks like this:

do_stuff do
stuff
end

where "stuff" is the part I want to wrap up into some tidy thing. I
tried it with lambda but my brain was too tired.

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com
 
T

Tim Hunter

Giles said:
Mil perdones, but my brain seems to have gone awol. I have multiple
places in a spec where I need to run the same block of code. I would
be much happier storing this block in a var as a Proc as opposed to
wrapping it up in a method. Is there a way I can do this? My spec
looks like this:

do_stuff do
stuff
end

where "stuff" is the part I want to wrap up into some tidy thing. I
tried it with lambda but my brain was too tired.

var = Proc.new { stuff }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top