Hello World

View saved

Write a file

Save this as hello.rb.

puts "Hello, World!"

Run it

Pass the filename to the Ruby interpreter.

ruby hello.rb

Print several values

puts adds a newline. print does not.

language = "Ruby"
puts "Learning", language
print "No newline"
puts " yet"

First habits

  • Ruby files use the .rb extension
  • Method calls often omit parentheses for simple cases
  • Everything is an object, including numbers and strings
  • Use IRB to experiment before saving a file

Comments

One comment per signed-in account. Comments are saved with this page’s URL.