Ruby – Assigning a block to a variable

On Friday, Brian and I were discussing how to assign a block to a variable in Ruby. I knew how to pass a block as a method argument def method(&proc), but I could not remember how to just assign a block to a variable. I finally looked up the syntax.

block = lambda { |word| puts word }block.call("adam")
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: