The source code to demonstrate the yield statement is given below. The given program is compiled and executed successfully.
# Ruby program to demonstrate the yield statement
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
Explanation:
In the above program, we used the "yield" statement to call block inside the method and printed the appropriate message.
Program/Source Code:
The source code to demonstrate the yield statement is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we used the "yield" statement to call block inside the method and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer