Created
January 20, 2016 06:15
-
-
Save mgrebenets/6d5e7014084de7641e45 to your computer and use it in GitHub Desktop.
Use of block.call vs yield
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
def platform_call(platform_name, &block) | |
puts "SupportedPlatforms.verify!(platform_name)" | |
puts "self.current_platform = platform_name" | |
block.call | |
puts "self.current_platform = nil" | |
end | |
def platform_yield(platform_name, &block) | |
puts "SupportedPlatforms.verify!(platform_name)" | |
puts "self.current_platform = platform_name" | |
yield | |
puts "self.current_platform = nil" | |
end | |
puts "Using block.call" | |
puts "" | |
platform_call("X") do | |
puts "---> block body on block.call" | |
end | |
puts "" | |
puts "Using yield" | |
puts "" | |
platform_yield("X") do | |
puts "---> block body on yield" | |
end | |
puts "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment