Skip to content

Instantly share code, notes, and snippets.

@mura303
Created September 23, 2008 05:49
Show Gist options
  • Save mura303/12222 to your computer and use it in GitHub Desktop.
Save mura303/12222 to your computer and use it in GitHub Desktop.
irb(main):001:0> def f1( x, y )
irb(main):002:1> yield( 1, 2, x, y )
irb(main):003:1> end
=> nil
irb(main):004:0> f1( 1,2 )
LocalJumpError: no block given
from (irb):2:in `f1'
from (irb):4
from :0
irb(main):005:0> f1( 1, 2 ) do |a,b,c,d| a+b+c+d end
=> 6
irb(main):006:0> f1( 9, 9 ) do |a,b,c,d| a*b*c*d end
=> 162
irb(main):007:0> f1( 1, 1 ) do |a,b| a + b end
=> 3
irb(main):008:0> f1( 100, 100 ) do |a| a end
(irb):8: warning: multiple values for a block parameter (4 for 1)
from (irb):2
=> [1, 2, 100, 100]
irb(main):009:0> yield
LocalJumpError: no block given
from (irb):9
from :0
irb(main):010:0> block_given?
=> false
irb(main):011:0> def f2
irb(main):012:1> block_given?
irb(main):013:1> end
=> nil
irb(main):014:0> f2
=> false
irb(main):015:0> f2 do 1 end
=> true
irb(main):016:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment