Learn Ruby Programming in 14 Days

Learn Ruby Programming in 14 Days

Written : Last Update :

This blog is still under progress and new Content is being added everyday.

This is a simple yet complete guide to learn Ruby Programming language in 14 hours/days. You can the time accordingly.

Day 0 - History and The Setup

Ruby is a dynamic, open-source programming language known for its simplicity and productivity. Since its creation in the mid-1990s by Yukihiro "Matz" Matsumoto, Ruby has gone through various versions and updates.

Features

  • Dynamically Typed
  • Object Oriented
  • Interpreted Language
  • Cross Platform
  • Clean and Readable Syntax

Ruby 0.95 (December 21, 1995): This was the first public release of Ruby, and it laid the foundation for the language. Ruby's initial development aimed at providing a more human-friendly and object-oriented scripting language.

Ruby 3.1 (December 25, 2021): Ruby 3.1 continued to build on the improvements of Ruby 3.0, introducing features like "Pattern Matching" enhancements and other optimizations. This is the version I will be using.

💎 Ruby files end with the extension .rb.

Setup

Installing on Windows

Installing on Linux

Installing on Mac Os

Online Editor

Ruby has an interactive online editor to try and run code even without any setup. You can try it here (opens in a new tab).

Interactive Ruby Shell

IRB ( Interactive Ruby Shell) can be used to immediately execute the Ruby statements. It can be launched by typing irb in the command shell.

irb

Running a Program

  1. Create a file with .rb extension. example hello.rb.
  2. Write some code to it, for example
puts "Hello From Desi Programmer"

Day 1 - Variables and Datatypes in Ruby

Once I have choosen a Setup, I will start with very basic stuff like printing text and variables and datatypes.

Printing on Console

print and puts can be used to print data on the terminal/command/shell window. puts places the content in the same line while print adds a line break by default moving the content to a new line.

puts "Welcome to Desi Programmer"
print "This is printed on new line"
puts "All this"
puts "on same line"

Output

Welcome to Desi Programmer
This is printed on new lineAll this
on same line

Variables in Ruby

Data Types in Ruby

Ruby is a dynamically typed language, which means that variables don't have explicit data types associated with them. Instead, the data type is determined by the value assigned to the variable.

Here are some common data types in Ruby

  1. Integer (Fixnum, Bignum) : Ruby has two types of integers, Fixnum and Bignum. Fixnum is used to represent small integers, while Bignum is used for large integers that can't fit into a Fixnum. Ruby automatically switches between these two types as needed.
videos = 200
non_views = 1_900_000_000 # Bignum
  1. Float : Float represents floating-point numbers (real numbers). Ruby uses double-precision floating-point numbers to represent decimal values.
pi = 3.14159
  1. String : Strings are used to represent text or sequences of characters. Ruby strings can be enclosed in single ('') or double ("") quotes, and they support string interpolation. String interpolation replaces variable in the string with the value of that variable.
name = "Alice"
message = "Hello, #{name}!"
  1. Boolean : Ruby has two boolean values, true and false, which are used for logical operations and conditional statements.
reading = true
liking_it = true
sharing_it = false
  1. Array : An array is an ordered collection of objects, which can be of any data type. Arrays are zero-indexed, and elements can be accessed by their index.
fruitsarr = ["apple", "banana", "orange"]
intarr = [98, 75, 88, 92]
hetero = ["apple", "banana", "orange", 23, 2.34]
  1. Hash : A hash is a collection of key-value pairs, where keys are unique and used to access values. Hashes are often used to represent data in the form of dictionaries or associative arrays.
person = { "name" => "John", "age" => 30, "city" => "New York" }
  1. Symbol : Symbols are lightweight and immutable identifiers. They are often used as keys in hash data structures and for efficiency in some cases.
status = :success
  1. Nil : nil is Ruby's way of representing the absence of a value or a null value.
result = nil
  1. Range : A range represents a sequence of values between a start and an end point. Ranges can be inclusive or exclusive and are often used in iterations and comparisons.
inclusive_range = 1..5 # Represents 1, 2, 3, 4, 5
exclusive_range = 1...5 # Represents 1, 2, 3, 4

Day 2 - Decisions - If/else, switch , ternary operators

Day 3 - Control Structures - Loops

Day 4 - Functions

Day 5 - Arrays and Maps

Day 6 - More on String and Numbers

Day 7 -

Day 8 -

Day 9 -

Day 10 -

Day 11 - Classes and Objects

Day 12 - More on Classes

Day 13 - Handling Files, text and json

Day 14 - Exceptions Handling