Skip to content

Instantly share code, notes, and snippets.

@picatz
Created August 28, 2017 04:20
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 picatz/7f280bea5b8cf05491df95fbb445d78c to your computer and use it in GitHub Desktop.
Save picatz/7f280bea5b8cf05491df95fbb445d78c to your computer and use it in GitHub Desktop.
module Blocks
NUMBERS = [1,2,3]
def self.require_block(&block)
NUMBERS.each do |number|
yield number
end
end
# because method overloading
def self.optional_block
NUMBERS
end
def self.optional_block(&block)
require_block do |number|
yield number
end
end
end
Blocks.require_block do |number|
puts number
end
Blocks.optional_block.each do |number|
puts number
end
Blocks.optional_block do |number|
puts number
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment