Created
June 27, 2015 00:06
-
-
Save domgetter/52ae28bc89e8d487d6c0 to your computer and use it in GitHub Desktop.
Examples of using blocks to achieve Inversion of Control in Ruby
This file contains hidden or 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
puts "hello" | |
# refactor to a method call | |
def hello | |
puts "hello" | |
end | |
hello | |
#refactor to invert control | |
def hello | |
yield | |
end | |
hello do | |
puts "hello" | |
end | |
#refactor to invert control | |
def hello | |
yield "hello" | |
end | |
hello do |phrase| | |
puts phrase | |
end | |
#refactor to invert control | |
def hello | |
puts yield | |
end | |
hello do | |
"hello" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment