Last active
October 27, 2019 18:31
-
-
Save Wolwer1nE/8303e471e1c1551af06e6e629d3f9a71 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
# Function prints results of block execution | |
# and prints message if no block was given | |
def function_that_can_accept_block(x, &block) | |
return "Wow, no block was given!" unless block_given? | |
block.call(x) | |
end | |
def some_other_function(x) | |
"I am a function and I print my input: #{x}" | |
end | |
# this will print an error message | |
p function_that_can_accept_block(1) | |
# this will print current time | |
p function_that_can_accept_block(Time.now) {|x| some_other_function(x)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment