Skip to content

Instantly share code, notes, and snippets.

@andrehjr
Created August 18, 2014 21:44
Show Gist options
  • Save andrehjr/4328db63fc086e12af3c to your computer and use it in GitHub Desktop.
Save andrehjr/4328db63fc086e12af3c to your computer and use it in GitHub Desktop.
Playing with blocks
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