Mega Code Archive

 
Categories / Ruby / Method
 

The yield Statement using the block_given method from Kernel

# the job of yield is to execute the code block that is associated with the method.    def gimme   if block_given?     yield   else     puts "I'm blockless!"   end end gimme { print "Say hi to the people." } # => Say hi to the people. gimme # => I'm blockless!