Last active
March 23, 2016 23:58
-
-
Save sebabelmar/2bca9bf53cc0296db546 to your computer and use it in GitHub Desktop.
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 do_twice | |
yield | |
yield | |
end | |
# The basics | |
do_twice {puts "HOLA"} | |
def do_something_to_an_array (array) | |
yield(array) | |
end | |
# Basics + Arguments | |
do_something_to_an_array([1,2,3,]) {|x| puts "Yeah... #{x}"} | |
def do_something_to_an_array_elements (arr) | |
i=0 | |
while i < arr.length | |
# We are gonna yield code instead of using a pre-define method | |
this_is_the_yield(arr[i]) | |
# You can comment line 23 and use line 25 and execute 36 instead of 35... | |
# yield(arr[i]) | |
i+=1 | |
end | |
end | |
def this_is_the_yield (some_sweet) | |
puts "im doing something with the element of the array #{some_sweet}" | |
end | |
# Yeah!! One way to use this... | |
do_something_to_an_array_elements([1,2,3,]) | |
# do_something_to_an_array_elements([1,2,3,]) {|y| puts y**2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment