Skip to content

Instantly share code, notes, and snippets.

@mgrebenets
Created January 20, 2016 06:15
Show Gist options
  • Save mgrebenets/6d5e7014084de7641e45 to your computer and use it in GitHub Desktop.
Save mgrebenets/6d5e7014084de7641e45 to your computer and use it in GitHub Desktop.
Use of block.call vs yield
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