RbRuby · Lesson 1 of 11

Hello, Ruby!

Ruby is famous for developer happiness. Matz (Ruby's creator) has said the language is optimized for programmer joy. Let's find out if he was lying.

In Ruby, you use `puts` (put string) to print to the console with a newline, or `print` if you want no newline. Ruby files end in .rb and are run with the ruby command.

Ruby
puts "Hello, World!"        # puts adds a newline
print "Hello, "             # print does not
puts "Ruby!"                # Hello, Ruby!

# p is like puts but shows the raw representation — great for debugging
p "hello"     # "hello" (with quotes)
p 42          # 42
p [1, 2, 3]   # [1, 2, 3]
p nil         # nil
Bash
# Save as hello.rb, then:
ruby hello.rb
◆ Note
Ruby doesn't require semicolons. Parentheses on method calls are usually optional — puts "hello" and puts("hello") are identical. Most Rubyists omit them for single arguments.
✦ Tip
Use `p` instead of `puts` when debugging. `puts` calls `.to_s` on the value (hiding the type), while `p` calls `.inspect`, showing you exactly what the object is — including nil vs empty string, and array brackets.