Created
August 18, 2014 21:44
-
-
Save andrehjr/4328db63fc086e12af3c to your computer and use it in GitHub Desktop.
Playing with blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def using_blocks(some_array) | |
some_array.each do |element| | |
yield element | |
end | |
end | |
using_blocks([1, 2, 3]) { |element| puts element * 2 } | |
using_blocks([1, 2, 3]) { |element| puts element - 1 } | |
def another_example(some_array) | |
some_array.each do |element| | |
yield element, element + 1 | |
end | |
end | |
another_example([1, 2 ,3]) { |element_1, element_2| puts "#{element_1} - #{element_2}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment