Using the ‘yield’ statement
It might be almost similar but relatively different in a big way for blocks may appear only in the source adjacent to a method call which means it should be written on the same line as the method’s last parameter and it is not implemented once it is encountered but, Ruby rather remembers the context by which the block of code appears then enters the method. Within the method itself, the block of code may be called as if it were a block in itself by using the ‘yield’ statement. After the block of code has been executed, control returns immediately right after the call to the yield statement. Sample use of ‘yield’:
def threeTimes
yield
yield
yield
end
threeTimes {puts “Hi There”}
