Skip to content

Yield

April 7, 2011

Some thoughts on yield.

def three_times
  yield
  yield
  yield
end

ruby-1.9.2-p0 :002 > three_times {puts "yes"}
yes
yes
yes
 => nil 

Yield can pass parameters

def one_two_three
  yield 1
  yield 2
  yield 3
end

ruby-1.9.2-p0 :014 > one_two_three{|v| puts "#{v}"}
1
2
3
Advertisements

From → Uncategorized

Leave a Comment

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: