Skip to content

Instantly share code, notes, and snippets.

@mleszcz
Last active May 9, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mleszcz/2b273d4ddbcd0ef7db6d8a2740b1f927 to your computer and use it in GitHub Desktop.
Save mleszcz/2b273d4ddbcd0ef7db6d8a2740b1f927 to your computer and use it in GitHub Desktop.
SOLID'nie
# In an object instance variable (denoted with '@'), remember a block.
def remember(&a_block)
@block = a_block
end
# Invoke the preceding method, giving it a block that takes a name.
remember {|name| puts "Hello, #{name}!"}
# Call the closure (note that this happens not to close over any free variables):
@block.call('Jon') # => "Hello, Jon!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment