Hello, World
The smallest Ruby program, and the difference between puts, print and p.
Runs in Zerethon IDE · Ruby 4.0
Official Ruby documentation ↗
A Ruby file runs from top to bottom; there is no main to declare. #{...} inside double quotes inserts the value of any expression.
main.rb
puts "Hello, World!"
puts "Sum: #{2 + 3}"
print "a", "-", "b", "!\n"
p [1, "two", nil]
Output
Hello, World! Sum: 5 a-b! [1, "two", nil]
putsadds a newline after each argument;printadds nothing;pshows the value as Ruby code (strings in quotes,nilvisible) — handy for debugging.- Single-quoted strings do not interpolate:
'#{x}'prints the characters as written. - A line starting with
#is a comment. Parentheses around method arguments are optional.