Skip to content

Instantly share code, notes, and snippets.

Created January 12, 2014 19:45
Show Gist options
  • Save anonymous/8389455 to your computer and use it in GitHub Desktop.
Save anonymous/8389455 to your computer and use it in GitHub Desktop.
Doubt with blocks & procs
def foo
p = block_given? ? Proc.new : nil
end
obj = foo{ |x| x + 1}
obj.call(3)
#=> 4
#How does this work? `Proc.new` in definition must have had the block as argument to give resulting Proc object.
#How does passed block to `foo` get passed in `Proc.new` ?
p = Proc.new
#ArgumentError: tried to create Proc object without a block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment