Skip to content

Instantly share code, notes, and snippets.

@Wolwer1nE
Last active October 27, 2019 18:31
Show Gist options
  • Save Wolwer1nE/8303e471e1c1551af06e6e629d3f9a71 to your computer and use it in GitHub Desktop.
Save Wolwer1nE/8303e471e1c1551af06e6e629d3f9a71 to your computer and use it in GitHub Desktop.
# 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