💎 Ruby — Learn From Zero

Playground: Replit Ruby | JDoodle — click, type, run.

What is Ruby?

Ruby is a elegant, object-oriented language focused on developer happiness. Famous for the Rails web framework.

  • Web apps (Ruby on Rails)
  • Scripts & automation
  • Prototyping
  • Dev tooling

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

ruby
puts "Hello, world!"

puts prints with a newline.

Variables

ruby
name = "Ada"
age = 36
height = 1.78
is_student = true

Dynamic typing, no declarations.

If / Else

ruby
age = 18
if age >= 18
  puts "Vote"
else
  puts "Too young"
end

Blocks end with end.

Loops

ruby
5.times { |i| puts i }
(0...3).each { |n| puts n }

Idiomatic iteration with blocks.

Methods

ruby
def greet(name)
  "Hello, #{name}!"
end
puts greet("World")

String interpolation with #{}.

Arrays & Hashes

ruby
fruits = ["apple", "banana"]
fruits << "cherry"
person = { name: "Ada", age: 36 }

Hashes are key-value stores.

🟡 Intermediate — Building Real Programs

Blocks & Procs

ruby
double = Proc.new { |x| x * 2 }
puts double.call(5)

Closures via blocks/procs/lambdas.

Classes

ruby
class Person
  attr_accessor :name
  def initialize(n); @name = n; end
end

Instance vars start with @.

Modules & Mixins

ruby
module Greetable
  def greet; "hi"; end
end
class User; include Greetable; end

Mixins add shared behavior.

Enumerables

ruby
nums = [1,2,3,4]
puts nums.select { |n| n.even? }

Rich Enumerable methods.

File I/O

ruby
File.write("a.txt", "Hi")
puts File.read("a.txt")

Simple file helpers.

🔴 Advanced — Pro Concepts

Metaprogramming

ruby
class Foo
  define_method(:bar) { "baz" }
end

Define methods at runtime.

Symbols

ruby
h = { name: "Ada" }
h[:name]

Symbols are immutable identifiers.

Exceptions

ruby
begin
  raise "oops"
rescue => e
  puts e.message
end

Use begin/rescue.

Gems & Bundler

ruby
gem "rails", "7.0"
# bundle install

Ruby's package ecosystem.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.