Ruby program to demonstrate the yield statement

bookmark

def MyMethod
    puts "Inside the method"
    yield
      
    puts "Hello from MyMethod"
    yield
end
  
MyMethod{puts "Hello from Block"}

 


Output:

Inside the method
Hello from Block
Hello from MyMethod
Hello from Block