Skip to content

Instantly share code, notes, and snippets.

@johntdyer
Created December 3, 2012 02:05
Show Gist options
  • Save johntdyer/4192150 to your computer and use it in GitHub Desktop.
Save johntdyer/4192150 to your computer and use it in GitHub Desktop.
BLock Test
#!/usr/bin/env ruby
def yield_noargs
puts "hi from yield_noargs"
yield if block_given?
end
def yield_args(foo)
puts "hi from yield_args"
puts "Was pased #{foo}"
yield if block_given?
end
def proc_onearg(&p)
puts "hi from proc_onearg"
p.call
end
def proc_twoarg(foo, &p)
puts "hi from proc_onearg"
puts "Was pased #{foo}"
p.call
end
yield_noargs
yield_noargs {puts "hi from the block"}
yield_args "foo"
# this has syntax error
# yield_args "foo", {puts "the block"}
proc_onearg {puts "hi from the block"}
# this has syntax error
# proc_twoarg "foo", {puts "hi from the block"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment