Ruby
Ruby is a dynamic, object-oriented language designed around developer happiness and readability — code often reads almost like English. It's best known for Ruby on Rails, the framework that popularized convention-over-configuration and powered a generation of startups, and it remains excellent for web apps, scripting, automation, and rapid product development.
Everything in Ruby is an object, and its expressive blocks and metaprogramming make it a joy for building elegant DSLs and concise code. Performance is usually "good enough" for product work, but you should still design thoughtfully and watch hot paths.
TL;DR
- Dynamic and object-oriented — everything is an object.
- Optimized for developer happiness and readable code.
- Rails dominates the ecosystem for full-stack web apps.
- "Good enough" performance for most products — design hot paths with care.
Quick Example
Blocks and chained iterators make transformations concise and readable:
Core Concepts
- Objects & classes — everything (even numbers) is an object with methods.
- Blocks, procs & lambdas — pass chunks of code to methods (
each,map,select). - Modules & mixins — share behavior across classes with
include(composition over inheritance). - Metaprogramming — Ruby can define methods and respond to messages at runtime (powerful, used heavily by Rails).
Ecosystem
- RubyGems — the package manager; libraries are "gems."
- Bundler — locks dependency versions (
Gemfile/Gemfile.lock). - Rails — the dominant full-stack web framework (MVC, convention-driven).
- RSpec / Minitest — testing; Sidekiq — background jobs.
Best Practices
- Pin and update dependencies; commit
Gemfile.lock. - Write tests (unit + integration) — the community has a strong testing culture.
- Keep code style consistent (RuboCop) and methods small.
- Be deliberate with metaprogramming and monkey patching — clever can become unmaintainable.
Comparison: Ruby vs Python
See Python.
Common Mistakes
Surprising monkey patches
Hidden performance cliffs
FAQ
Ruby or Python?
Both are dynamic, readable, and productive. Ruby's sweet spot is web development (Rails) and elegant DSLs, with blocks deeply woven into the language. Python dominates data science/ML and general scripting. Choose by ecosystem fit — Rails for a batteries-included web app, Python for data-heavy work.
Is Ruby still relevant?
Yes — Rails remains a fast, productive way to build and ship web products, and powers many large companies (GitHub, Shopify, Basecamp). It's not the trendiest choice, but it's mature, well-supported, and excellent for rapid development.
What makes blocks special?
Blocks are anonymous chunks of code passed to methods, central to idiomatic Ruby (each, map, select, times). They make iteration and resource management (File.open { ... }) concise, and underpin Ruby's expressive DSLs.
How fast is Ruby?
Historically slower than compiled languages, but modern Ruby (3.x) brought significant speedups (YJIT) and concurrency improvements. For most web products it's fast enough; for CPU-bound hot paths, profile and optimize or offload to a faster service.
Related Topics
- Python — The frequent comparison
- REST API Design — Building Ruby/Rails APIs
- Testing — Ruby's strong testing culture
- Background Jobs — Sidekiq and async work
- Programming Languages — The broader landscape