No history yet

Introduction to Ruby

Meet Ruby

In the mid-1990s, a Japanese programmer named Yukihiro Matsumoto, often called "Matz," set out to create a new programming language. He wanted something that was genuinely object-oriented and easy to use. He wasn't trying to build the fastest or most complex language. Instead, he wanted to create a language optimized for programmer happiness and productivity.

The result was Ruby. Its design philosophy is simple: programming should feel natural. The syntax is clean and readable, often resembling plain English. Matz blended his favorite parts of other languages like Perl, Smalltalk, and Lisp to create a language that is both powerful and elegant.

Ruby is designed to make programmers happy.

What Makes Ruby Special?

One of Ruby's core principles is that everything is an object. In many languages, numbers and other primitive types aren't objects, but in Ruby, they are. This means they have methods you can call on them, just like any other object. This leads to very expressive code.

5.times do
  puts "Ruby is fun!"
end

# This will print the string five times.

This consistency makes the language predictable and easier to learn. Ruby is also dynamically typed, which means you don't have to declare the type of a variable before you use it. The interpreter figures it out at runtime. This allows for rapid development and flexibility.

Getting Set Up

To start writing Ruby, you need to install it on your computer. The easiest way is to use a version manager. Tools like rbenv or RVM (Ruby Version Manager) let you install and switch between different versions of Ruby, which is helpful when working on multiple projects.

Once Ruby is installed, you just need a plain text editor to write your code. You don't need a fancy Integrated Development Environment (IDE), though many programmers use editors like Visual Studio Code, Sublime Text, or Atom for features like syntax highlighting.

Lesson image

Your First Program

Let's write the traditional first program: "Hello, World!". Open your text editor, create a new file, and save it as hello.rb. The .rb extension tells everyone that it's a Ruby file.

Inside that file, type the following line:

puts "Hello, World!"

That's it. The puts command is Ruby's way of printing a string of text to the console, followed by a new line. It's short for "put string."

To run your program, open your command line or terminal, navigate to the directory where you saved hello.rb, and type:

ruby hello.rb

Press Enter, and you should see Hello, World! printed on your screen. You've just written and executed your first Ruby program.

Time to check your understanding of these core concepts.

Quiz Questions 1/5

Who created the Ruby programming language and what was the primary philosophy behind it?

Quiz Questions 2/5

In Ruby, fundamental data types like numbers are treated as objects.