» Quick Introduction to Ruby » 1. Basics » 1.1 Hello World

Hello World

Ruby is a very flexible language that gives the programmer a lot of power. Ruby is focused on programmer productivity over machine optimization.

Let's start with the classic "Hello World."

puts "Hello World"

puts is a method that stands for "put string." It is used to output text or values to the console, followed by a newline character.

Comments

Single-line comments start with the # symbol and extend to the end of the line.

Multi-line comments can be enclosed between =begin and =end, but it's more common in Ruby to use the # symbol for both single-line and inline comments.

# This is a single-line comment

=begin
   This is a multi-line comment.
   It starts with =begin and ends with =end.
=end

Philosophy

"Ruby is a language for clever people." - Matz

Everything is an Object

Unlike Java, absolutely everything in Ruby is an object. Even a literal number (like 58) is an object with methods.

For example:

58.to_s # => 58
58.class # => Integer

Code Challenge

Try to modify the code in the editor to make it print Hello, Ruby! I'm a Rubyist..

Loading...
> code result goes here
Next