Skip to content

Instantly share code, notes, and snippets.

@yangsu
Created January 28, 2013 03:44
Show Gist options
  • Save yangsu/4652852 to your computer and use it in GitHub Desktop.
Save yangsu/4652852 to your computer and use it in GitHub Desktop.
Ruby Call Block
def call_block(&block) # NOTE: block is actually an instance of Proc
block.call 1, 2
end
call_block { |a,b| puts "Hello #{a} and #{b}" } # "Hello 1 and 2"
def yield_params
yield 1, 2
end
yield_params { |a,b| puts "#{a} and #{b}" } # "1 and 2"
# Example of instantiating a proc
someProc = Proc.new do
# do stuff here
end
otherProc = lambda do
# do other stuff here
end
puts someProc.class # Proc
puts otherProc.class # Proc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment