Ruby program to demonstrate the BEGIN and END blocks
BEGIN {
puts "Statement in BEGIN block";
}
END {
puts "Statement in END block";
}
# Below statements will execute
# before END block
puts "Message1";
puts "Message2";
Output:
Statement in BEGIN block
Message1
Message2
Statement in END block
