# basic block 10.times do |i| #puts i end # calling a block using a lambda function variable printFunc = proc do |i| puts i end [1, 2, 3].each( &printFunc ) # how blocks work def useBlocks yield( 5 ) yield( 10 ) end useBlocks do |var| puts "i was called with the parameter #{var}" end # how 5.times works def loopTimes( count ) for i in 0...count yield( i ) end end loopTimes( 5 ) do |i| puts i end # how to check for blocks def checkBlock if block_given? yield else puts "no block given" end end checkBlock checkBlock do puts "block given" end