Intro to Ruby
Designed for programmer happiness. Elegant, expressive, and beautiful code.
Designed for programmer happiness. Elegant, expressive, and beautiful code.
Ruby was born from one programmer's belief that coding should make you happy. Not just productive. Happy.
Companies built with Ruby:
Ruby's Hello World is one of the simplest of any programming language. One word, one string, done.
That's it. No imports, no main function, no semicolons. puts prints a line. Ruby gets out of your way.
String interpolation with #{} lets you embed expressions directly inside strings. No concatenation needed.
irb is Ruby's REPL. Type an expression, get the result instantly. The => shows the return value of every expression.
In most languages, numbers are just numbers. In Ruby, numbers are objects. Strings are objects. Even true and nil are objects. Everything has methods.
5.times { puts "hi" }
-42.abs
3.even?
"hello".reverse
"hello".length
"hello".include?("ell")
[3, 1, 2].sort
[1, 2, 3].sum
[1, 2, 3].sample
nil.class
nil.nil?
nil.to_s
This is what "pure object-oriented" means. You never have to wonder if something is an object. It always is.
Method chaining: the beauty of Ruby
Count from 1 to 10, keep only odd numbers, square each one. Reads almost like English.
Blocks are Ruby's most distinctive feature. They let you pass a chunk of code to a method. Instead of writing loops, you tell collections what to do with each item.
The essential iterators:
.select means "keep the ones where this is true." .map means "transform each one like this." The code reads like your intention.
Ruby's philosophy is simple: optimize for developer happiness. Every design decision asks, "Does this make the programmer's life better?"
Ruby was designed so programmers enjoy writing code. Readable syntax, intuitive naming, minimal boilerplate. The language respects your time.
There's more than one way to do things. Use unless instead of if-not. Use until instead of while-not. Pick the style that reads best for your situation.
Rails popularized this idea: sensible defaults mean you write less configuration and more actual code. Follow the convention, skip the setup.
RubyGems hosts 170,000+ libraries (called "gems"). Need authentication? There's a gem. Payments? Gem. PDF generation? Gem. One command installs it.
The framework that put Ruby on the map. Full-stack web development with database migrations, routing, templating, and testing built in. Startups love it.
Ruby has the strongest testing culture of any language. RSpec, Minitest, and Capybara make writing tests feel natural, almost like writing documentation.
Open the terminal and start writing Ruby. Here's how to get going in under a minute.
apt install rubynano hello.rbruby hello.rbirb opens an interactive session. Type expressions, see results instantly.Mini-project: Number Guessing Game
Save this as guessing_game.rb and run it with ruby guessing_game.rb. Notice how readable the code is, even if you have never seen Ruby before.
You've explored the language designed for programmer happiness. Ruby proves that code can be powerful and beautiful at the same time. Go write something elegant.
Numbers, strings, booleans, even nil. In Ruby, everything you touch is an object with methods you can call.
Blocks let you pass behavior to methods. They make Ruby code concise, expressive, and surprisingly readable.
Ruby on Rails (2004) proved you could build web apps in days, not months. It shaped how modern frameworks work.
Ruby was built so programmers could be happy. Readable syntax, multiple ways to solve problems, and a community that cares about craft.
Put your new knowledge into practice!