Introduction to Ruby

Ruby is a dynamic, beginner-friendly programming language designed for programmer happiness and readable code that reads almost like plain English.

Learn Introduction to Ruby in our free Ruby course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free Ruby course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll understand what Ruby is and why it exists, how it runs your code, and you'll have written and run your own first Ruby script that prints to the screen.

What You'll Learn in This Lesson

1️⃣ What is Ruby?

Ruby is a dynamic, object-oriented language created in Japan by Yukihiro "Matz" Matsumoto and first released in 1995. Matz blended pieces he loved from other languages and added a single guiding principle: the language should make programmers happy . That philosophy shows up everywhere:

You'll start where every Ruby developer starts: a tiny script that prints text. Read the worked example below — every line is explained — then run it yourself.

2️⃣ Why Ruby Feels Different: Readable, Object-Oriented Code

Two things make Ruby feel friendly. First, the syntax stays out of your way — blocks use do...end and conditions can even trail the line they affect. Second, because everything is an object, you call methods on values directly, and many method names end in ? (a question, returns true/false) or ! (a warning, changes things). Read the comments, predict each line's output, then check.

Notice how puts "Keep coding" unless hungry reads almost like a sentence. That trailing unless is pure Ruby flavour — it keeps simple guards short and clear.

Your turn. The script below works once you replace the two TODO markers. Follow the 👉 hints, then run it and compare with the expected output.

3️⃣ Running a File with the ruby Command

To run a Ruby script on your own machine, save it in a file ending in .rb (for example hello.rb ) and type ruby hello.rb in your terminal. Ruby reads the file top to bottom and prints anything you puts to the screen.

No blanks this time — just a brief and an outline. Write it yourself, run it with ruby info.rb , and check your output against the example in the comments.

📋 Quick Reference — Ruby Basics

Practice quiz

Who created Ruby and what was its guiding goal?

  • Matz, for programmer happiness
  • Guido, for readability
  • Larry Wall, for flexibility
  • Brendan Eich, for the browser

Answer: Matz, for programmer happiness. Yukihiro Matsumoto (Matz) designed Ruby around programmer happiness.

Which method prints a line of text and adds a trailing newline?

  • print
  • puts
  • echo
  • write

Answer: puts. puts adds a newline; print does not.

What does puts 42.class output?

  • 42
  • Number
  • Integer
  • Fixnum

Answer: Integer. In Ruby everything is an object; a whole number is an Integer.

Which syntax interpolates a value into a string?

  • $(name)
  • {name}
  • #{name} inside double quotes
  • %name%

Answer: #{name} inside double quotes. String interpolation uses #{...} inside double quotes.

Does string interpolation work inside single quotes?

  • yes, always
  • no, only double quotes
  • only with a backslash
  • only for numbers

Answer: no, only double quotes. Single quotes print #{...} literally; use double quotes.

How do you run a Ruby script named hello.rb from the terminal?

  • run hello.rb
  • ruby hello.rb
  • exec hello.rb
  • rb hello.rb

Answer: ruby hello.rb. The ruby command followed by the filename runs the script.

What does 3.times do ... end do?

  • runs the block 3 times
  • returns the number 3
  • counts to 3 and stops the program
  • raises an error

Answer: runs the block 3 times. times is an iterator that runs the block that many times.

What does "".empty? return?

  • false
  • true
  • nil
  • 0

Answer: true. An empty string is empty, so empty? returns true.

By convention, a method name ending in ? usually:

  • mutates the object
  • returns true or false
  • raises an exception
  • is private

Answer: returns true or false. A trailing ? marks a predicate that returns a boolean.

Which built-in constant holds the running Ruby version?

  • VERSION
  • RUBY_VERSION
  • RubyVersion
  • RUBY

Answer: RUBY_VERSION. RUBY_VERSION is the built-in constant for the interpreter version.