Different commands for the same purpose in Ruby

The Ruby programming language is free and open source. It is both object-oriented and interpretive. Yukihiro Matsumoto invented Ruby. Ruby’s founder referred to it as the jewel of programming languages because it was named after a gemstone. Here, we’ll talk about the various Ruby commands.

The following criteria were taken into account during the development of Ruby:

  • Simplicity
  • Extensiveness
  • Completeness
  • Portability

Most UNIX-based platforms support Ruby. Ruby was primarily developed on Linux. Common platforms like Windows, DOS, macOS, etc., are all compatible with Ruby.

1. Print Educative Answer in RUBY

puts "Educative, Answer!"

2. BEGIN statement to print line in the start

puts "This statement comes later"
BEGIN {
puts "This statement will be printed in the beginning"
}

3. EOF statement to print multiple lines

print <<"EOF";
Multiple line string.
1:E
2:D
3:U
4:C
5:A
6:T
7:I
8:V
9:E
EOF

4. EOC command to print multiple lines

print <<`EOC`
echo E
echo D
echo U
echo C
echo A
echo T
echo I
echo V
echo E
EOC

5. Ruby END statement to print line in the end

puts "This is main body"
END {
puts "This block executes in the end"
}
BEGIN {
puts "This block executes in the beginning"
}

6. Stacking command to print multiple lines

print <<"Answers", <<"Courses" # you can stack them
Educative Answers is a valuable platform.
Answers
Educative courses can provide deep view of you selected course.
Courses

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved