Ruby is a dynamic, interpreted, object-oriented programming language created by Yukihiro Matsumoto and first released in 1995, designed around the principle that code should be pleasant for humans to read and write. Among general-purpose languages in programming, Ruby stands out for treating every value as an object, for its expressive block syntax and for strong support for metaprogramming, which lets programs define and modify their own behavior at runtime.
Ruby gained global adoption through Ruby on Rails, the web framework released in 2004 that popularized convention over configuration and rapid application development. Today Ruby remains a common choice for web back ends, developer tooling, automation scripts and domain-specific languages, while its performance has improved substantially through successive interpreter releases.
How Ruby executes code
Ruby source code is executed by an interpreter that compiles it to bytecode for a virtual machine rather than to native machine code ahead of time. The reference implementation, known as CRuby or MRI, has used the YARV virtual machine since Ruby 1.9, and recent versions add YJIT, a just-in-time compiler that translates frequently executed bytecode into native instructions.
CRuby uses a Global VM Lock (GVL), which allows only one thread to execute Ruby code at a time within a process. Threads still help with input and output bound work such as network calls, because the lock is released while waiting, but CPU-heavy parallelism traditionally requires multiple processes. Ruby 3.0 introduced Ractors, an actor-style model that enables true parallel execution with isolated object spaces, although adoption remains limited.
The following table summarizes the main Ruby implementations and where each fits.
| Implementation | Runtime basis | Typical use |
|---|---|---|
| CRuby (MRI) | YARV bytecode VM with optional YJIT | Default for most applications |
| JRuby | Java Virtual Machine | Java integration, real thread parallelism |
| TruffleRuby | GraalVM with partial evaluation | High peak performance experiments |
| mruby | Lightweight embeddable VM | Embedded devices and game scripting |
Core language features of Ruby
Ruby is purely object-oriented: integers, strings, nil and even classes are objects that respond to methods, so an expression such as 5.times { puts "hi" } is ordinary Ruby. The language uses dynamic typing with duck typing, meaning an object is judged by the methods it responds to rather than by its declared class.
Blocks are anonymous chunks of code passed to methods with do...end or braces, and they underpin iteration, resource management and callbacks. Ruby replaces multiple inheritance with mixins: a class can include one or more modules to share behavior, as the Enumerable and Comparable modules demonstrate across the standard library.
The table below lists features that shape everyday Ruby code.
| Feature | What it provides | Practical effect |
|---|---|---|
| Blocks and iterators | Code passed to methods | Concise loops and resource handling |
| Mixins via modules | Shared behavior without multiple inheritance | Reusable traits across classes |
| Open classes | Reopening existing classes at runtime | Extensions, but risk of conflicts |
| method_missing | Handling of undefined method calls | Dynamic proxies and DSLs |
| Symbols | Immutable interned identifiers | Efficient hash keys and names |
| Garbage collection | Automatic memory management | No manual allocation or freeing |
Metaprogramming tools such as define_method, instance_variable_get and send allow libraries to generate methods dynamically. This power explains the readable internal DSLs found in tools like RSpec and Rake, but it also makes static analysis and code navigation harder than in explicitly typed languages.
The Ruby ecosystem and tooling
Ruby libraries are distributed as gems through the RubyGems package manager, and Bundler resolves and locks dependency versions per project in a Gemfile.lock. Version managers such as rbenv, chruby and asdf let developers run several Ruby versions side by side.
Beyond Rails, the ecosystem includes Sinatra for lightweight web services, Sidekiq for background job processing, RSpec and Minitest for testing, and RuboCop for style enforcement. Optional static typing is available through RBS signature files, shipped with Ruby 3.0, and through Sorbet, a gradual type checker developed for large codebases.
Ruby compared with related languages
Ruby is most often compared with other dynamic languages used for web development and scripting. Its closest relative in philosophy is Python, while its main web competitors include PHP and JavaScript on Node.js.
| Language | Typing | Design emphasis | Dominant domain |
|---|---|---|---|
| Ruby | Dynamic, duck typing | Expressiveness and developer happiness | Web applications, tooling |
| Python | Dynamic, optional hints | One obvious way to do things | Data science, scripting, web |
| PHP | Dynamic, optional declarations | Pragmatic server-side web | Content management, web |
| JavaScript | Dynamic, prototype-based | Ubiquity in browsers | Front end and Node.js back ends |
| Go | Static, compiled | Simplicity and concurrency | Cloud services, infrastructure |
The key contrast with Python is cultural: Ruby tolerates many ways to express the same idea, whereas Python favors a single idiomatic form. Compared with Go or Java, Ruby trades raw execution speed and compile-time safety for faster iteration and shorter code.
When to choose Ruby
Ruby is a strong choice when time to market and code clarity matter more than maximum throughput. The decision table below maps common situations to a recommendation.
| Situation | Recommendation | Reason |
|---|---|---|
| Database-backed web product | Ruby with Rails | Mature conventions and fast delivery |
| Build and automation scripts | Ruby is suitable | Readable syntax and rich standard library |
| CPU-intensive numerical work | Prefer another language | Limited numeric ecosystem and GVL |
| Low-latency systems software | Prefer Rust, Go or C++ | Garbage collection and interpreter overhead |
| Internal domain-specific language | Ruby is well suited | Blocks and metaprogramming enable DSLs |
Limitations and common pitfalls
The most cited weakness of Ruby is performance relative to compiled languages, although YJIT has narrowed the gap for typical web workloads. Memory consumption per process can be high, which matters because scaling often relies on multiple worker processes rather than threads.
- Monkey patching core classes can create conflicts between gems and surprising behavior.
- Heavy metaprogramming makes code difficult to trace and to refactor safely.
- Dynamic typing defers many errors to runtime, so thorough automated testing is essential.
- Rails conventions speed up delivery but can hide costly database queries such as the N+1 query problem.
The simple explanation
Ruby is a way of writing instructions for a computer that tries to read almost like plain English. Its creator wanted programmers to enjoy writing code, so Ruby lets you express an idea in few words.
Think of it as a well-organized kitchen where every tool is within reach. You can cook quickly and creatively, although a professional industrial kitchen might produce meals faster at huge scale. In short, Ruby favors speed of building over speed of running, which makes it popular for websites and online services.
How it is used in practice
A small team of four developers at a regional logistics startup needs a customer portal where clients book shipments, track parcels and download invoices. They choose Ruby on Rails because its generators, built-in database migrations and conventions let them model shipments, customers and invoices in days rather than weeks.
Within six weeks the team ships a working portal backed by PostgreSQL, uses Sidekiq background jobs to send tracking emails and runs an RSpec suite of about 900 tests on every commit. As traffic grows, they enable YJIT and add Puma worker processes, keeping median response times under 150 milliseconds without rewriting the application in another language.