Last active
May 9, 2018 10:46
-
-
Save mleszcz/2b273d4ddbcd0ef7db6d8a2740b1f927 to your computer and use it in GitHub Desktop.
SOLID'nie
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
# 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