Ruby Overview

Photo by Taskin Ashiq on Unsplash
Photo by Taskin Ashiq on Unsplash

Introduction to Ruby

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language.

History

Ruby was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.¬†According to its creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.

Ruby Resources

Quick Reference – Ruby

Here is a quick reference for the basics of Ruby…

Hello World in Ruby

puts 'What is your name?'
yourName = gets.chomp
puts "Hello #{yourName} !"

Ruby: Basic Syntax

Variables & Data Types

No types or special naming conventions.

Branching

if (condition)
  # do something
elsif (condition)
  # do something
else
  # do something
end

Arrays

primeNumbers = [2, 3, 5, 7, 11]

Loops

You can loop through all the items in an array:

myArray = ["one", "two", "three", "four", "five"]
myArray.each do |item|
  puts item
end

You can loop a fixed number of times:

number = 0
5.times() do
  number = number + 1
  puts number
end

You can loop while a condition is true:

while (condition == true) 
  # do something that may change the condition
end

You can loop until a condition is false (always loops once):

loop do 
  # do something 
  if (condition)
    break
  end
end

Books on Ruby