What is Ruby and where it runs

What Ruby is

Ruby is a dynamic interpreted language created by Yukihiro Matsumoto, known as Matz. You write plain text, and the Ruby interpreter reads the whole file, compiles it to bytecode and runs it, with no build step you have to type.

Everything in Ruby is an object, even numbers and strings, so you can call methods on any value. The Ruby hub page collects every guide of the course.

puts "Hello from Ruby" # prints Hello from Ruby puts 2 + 2 # prints 4

Where Ruby runs

Ruby runs on Linux, macOS, and Windows, so one script can travel between machines with almost no changes. Developers use it for small automation scripts, command line tools, servers, and full web applications.

The interpreter itself can tell you which version is active through a built-in constant:

puts RUBY_VERSION # prints something like 3.2.2

Why learn Ruby

Ruby reads almost like plain English, which makes it a friendly first language. Short programs stay short, and the error messages usually point at the exact line that needs attention.

Ruby also teaches habits that transfer to other languages: objects, methods, blocks, and tests. Many teams still build products with Ruby on Rails, while others use plain Ruby for scripts and DevOps tasks.

Matz is nice

Matz designed Ruby for programmer happiness, and the community motto says it well: Matz is nice and so we are nice. Code should surprise you as little as possible and read from top to bottom with ease.

Here is a small taste of that readability. Even before you know the syntax, you can probably guess what happens next:

names = ["Ada", "Matz"] names.each do |name| puts name end

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. Who created Ruby?

    Answer

    Yukihiro Matsumoto, known as Matz

    Matz wrote Ruby in 1995 and still leads its design.

  2. What does this program print? puts 2 + 2

    Answer

    4

    The addition happens before puts, which prints the number 4.

  3. Which command runs the script hello.rb?

    Answer

    ruby hello.rb

    The interpreter is the program, and the script is its argument.

  4. What does this program print? names = ["Ada", "Matz"] names.each { |name| puts name }

    Answer

    Ada / Matz, each on its own line

    each calls the block once per element, and puts ends every line.

  5. Which constant holds the version of the running interpreter?

    Answer

    RUBY_VERSION

    RUBY_VERSION is a string such as "3.4.12"; RUBY_ENGINE names the interpreter instead.

  6. What is true of values in Ruby?

    Answer

    Everything is an object, so every value has methods

    Even an integer is an object: 4.even? and "ada".upcase both work.

  7. What does this program print? word = "Ruby" puts word.upcase

    Answer

    RUBY

    upcase returns a new string in capitals; puts prints that.

  8. On which systems can a Ruby script run?

    Answer

    Linux, macOS and Windows

    The interpreter exists for all three, so one script usually moves between them unchanged.

  9. What does a Ruby script need before the interpreter can run it?

    Answer

    Nothing: the .rb text file is enough

    The interpreter compiles the file itself, so the source is all you save.

  10. What is the community motto that this lesson quotes?

    Answer

    Matz is nice and so we are nice

    The motto is shortened to MINASWAN and shapes how the community reviews code.

Article author: Arthur Isaev