Ruby Tutorial
Master Ruby from scratch with our comprehensive, interactive curriculum — 50 lessons from Beginner to Advanced.
Learn Ruby from scratch — strings, arrays, hashes, blocks, classes, modules, metaprogramming and an intro to Rails — free interactive lessons.
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.
Start with Lesson 1 and build real skills step by step — at your own pace.
Lessons in this course
- Introduction to Ruby — Install Ruby, run your first script, and understand how Ruby works
- Variables & Types — Store text, numbers, booleans, and nil — and check their types
- Strings & Symbols — Build and interpolate strings, and learn what symbols are for
- Numbers & Math — Integers, floats, arithmetic, and handy numeric methods
- Control Flow — Make decisions with if, unless, case, and ternary expressions
- Methods — Define reusable methods with parameters, defaults, and return values
- Blocks — Pass chunks of code to methods with do...end and curly braces
- Arrays — Create, index, and transform ordered lists of values
- Hashes — Store and look up data with key-value pairs
- Ranges — Express sequences of numbers and letters concisely
- Procs & Lambdas — Store blocks of code in variables and pass them around
- Iterators & Enumerable — Loop and transform collections with each, map, select, and reduce
- Classes & Objects — Model real-world things with classes, instances, and methods
- Attributes (attr_accessor) — Generate getters and setters automatically for instance data
- Modules & Mixins — Share behaviour across classes and namespace your code
- Exception Handling — Rescue errors gracefully with begin/rescue/ensure
- Regular Expressions — Match, extract, and replace text patterns with regex
- File I/O — Read from and write to files safely on disk
- Metaprogramming Intro — Write code that writes code with send, define_method, and method_missing
- Gems & Bundler — Install libraries with gem and manage dependencies with Bundler
- Intro to Rails — Meet the Rails web framework and the MVC pattern
- Operators & Expressions — Arithmetic, comparison, logical, the spaceship <=>, and parallel assignment
- nil, true, false & Truthiness — Only nil and false are falsy — plus &. , ||= and safe nil handling
- Loops (while, until, loop) — while/until, loop/break, times/upto/step, and next/break/redo
- case/when Conditionals — Branch with === — matching ranges, classes, and regex in when
- String Methods — Interpolation, gsub/sub, split/join, format, and the bang methods
- Advanced Enumerable (reduce, group_by, chunk) — reduce, group_by, partition, each_with_object, sort_by, tally
- Struct & OpenStruct — Lightweight value objects with Struct, keyword_init, and Data.define
- Sets — Unique collections with union, intersection, difference, and subset?
- Checkpoint: Ruby Basics — Combine operators, enumerable, Struct and Set in a build — then a quiz
- Inheritance & super — Subclassing, super, method overriding, and protected/private
- self, Class Methods & Class Variables — What self means, def self.method, and @@ vs class instance variables
- Constants & Freezing — Constant scoping with ::, freeze/frozen?, and frozen string literals
- Pattern Matching (case/in) — Deconstruct arrays and hashes with case/in, guards, and find patterns
- Custom Exception Classes — Build an exception hierarchy with custom messages, retry, and ensure
- Dates & Times — Time, Date and DateTime — strftime formatting, parsing, and arithmetic
- JSON & YAML — Parse and generate JSON and YAML, and round-trip Ruby hashes
- Testing with Minitest — Write assertions, setup, and assert_raises with the built-in Minitest
- Checkpoint: OOP & Stdlib — Combine inheritance, custom errors and JSON in a build — then a quiz
- Custom Iterators & Enumerator — Make your objects work with map/select by defining each and including Enumerable
- Method Arguments (Keyword, Splat, Block) — Positional, keyword, *args, **kwargs, and &block arguments
- The Comparable Module — Define <=> and get <, >, between?, and clamp for free
- Refinements — Safely scope monkey-patches with refine and using
- Fibers & Lazy Evaluation — Pause and resume code with Fiber to build lazy sequences
- Threads, Mutex & Ractor — Concurrency with threads, safe state via Mutex, and a look at Ractor
- Automation with Rake — Define tasks, dependencies, and namespaces in a Rakefile
- CLI Scripts with OptionParser — Parse ARGV into clean options for real command-line tools
- Benchmarking & Profiling — Compare approaches and find hot spots with the Benchmark module
- Checkpoint: Advanced Ruby — Combine Comparable, a lazy Enumerator and threads in a build — then a quiz
- Capstone: A CLI App — Combine everything to build a real command-line application
- Rails Project Structure & MVC — rails new, the app/ layout, the MVC request flow and convention over configuration
- Routing & RESTful Resources — config/routes.rb, resources, the seven RESTful routes and route helpers
- Controllers & Actions — Actions, params, render/redirect_to and before_action filters
- Views, ERB & Partials — ERB tags, layouts, partials and view helpers
- ActiveRecord Models & Migrations — Models, migrations, the schema and CRUD with the ORM
- Associations — has_many, belongs_to, has_many :through and many-to-many
- Validations & Callbacks — Validate presence/uniqueness/format, errors and lifecycle callbacks
- Forms & Strong Parameters — form_with, strong parameters, CSRF protection and flash
- REST APIs & Authentication — API mode, JSON responses, sessions, has_secure_password and Devise
- Capstone: A Rails Blog App — Build a full blog with posts, comments, auth and tests end to end
- Testing with RSpec — describe/it, matchers, let/subject, mocks and stubs — the dominant Ruby test tool
- Sinatra & Rack — The Rack interface every Ruby web app runs on, and the Sinatra micro-framework
- Background Jobs with Active Job & Sidekiq — Move slow work off the request with Active Job, Sidekiq and Redis
- Hotwire, Turbo & Action Cable — SPA-like Rails with Turbo Drive/Frames/Streams, Stimulus and Action Cable
- Building & Publishing a Gem — Create a gemspec, structure lib/, and publish to RubyGems.org