Codectionary / Developer documentation / Ruby

Start here to understand Ruby, where it came from, what people build with it, and how a short Ruby program works. No previous programming experience is needed.

File extension
.rb
Runs in
Ruby interpreter

What Ruby is

Ruby is a general-purpose programming language: you can use it to write instructions for many kinds of software, from a small file-processing script to a web service. Its source files commonly end in .rb. A Ruby implementation reads and executes the program; the most common implementation is CRuby, often called MRI. Ruby the language is distinct from Ruby on Rails, which is a web framework written in Ruby.

Ruby lets you start with a few lines of code, then organise a growing program into methods, classes and modules. A method is a named operation you can reuse. A class describes a kind of object. A module groups related behaviour or names. You do not need to learn all three before writing your first program.

From Japan to a worldwide language

Yukihiro Matsumoto, widely known as Matz, began designing Ruby in Japan in 1993. He wanted an object-oriented scripting language that felt natural to use. He drew ideas from languages including Perl, Smalltalk, Eiffel, Ada and Lisp, then made his own choices about how they should fit together. Ruby 0.95 was announced to Japanese newsgroups in December 1995, its initial public release.

Ruby grew from a scripting language into an ecosystem used for web applications, tools and tests. Ruby on Rails brought many developers to the language in the 2000s. Ruby itself has kept evolving through new releases, libraries and implementations. A particular project still needs a compatible Ruby version and compatible dependencies; a feature shown in current documentation may not work on an older installation.

Why Ruby values the programmer’s experience

Matz designed Ruby around the experience of the person writing and reading code. Ruby often lets you express an idea with familiar words and modest punctuation. For example, the expression 3.times { puts "Hello" } asks Ruby to print a line three times. The goal is to make a program easier to understand and change, not to claim that short code is always good code.

Readability matters when you return to your own work weeks later or review a teammate’s change. Productive code can help a team test an idea quickly, but it still needs clear names, tests and attention to error cases. Ruby offers several ways to express some tasks; choose the one your reader can follow, even if another spelling is shorter.

Values have types, but variables do not declare one

Ruby is dynamically typed. A value such as 12 is an Integer object and "twelve" is a String object, but a variable name does not normally declare a fixed type. You can assign a number to a name such as answer and later assign text to the same name. Ruby checks whether an operation works with the actual objects when that operation runs.

Dynamic typing does not mean that types are ignored. Adding two numbers works; adding a number directly to a string raises an error unless you convert or otherwise handle the values. This flexibility makes experiments quick, but a type mismatch may only appear on a path you execute later. Tests, clear interfaces and explicit validation of outside input remain useful.

Ruby — types are checked when an operation runs

answer = 12
puts answer.class  # Integer
answer = "twelve"
puts answer.class  # String

What object-oriented Ruby means

Object-oriented programming groups data and operations together. An object has a type, represented by its class, and responds to methods. In Ruby, strings, arrays and even integers are objects: "hello".upcase asks a String object for uppercase text, while [1, 2].length asks an Array for its size. This shared model makes many APIs feel consistent.

You can create your own classes when a program needs a meaningful kind of object, such as an Order with a total. Ruby also supports straightforward scripts and reusable methods; you do not need to wrap every line in a class. Blocks—pieces of code passed to methods—make everyday operations such as iterating over an array expressive.

How Ruby compares with Python and JavaScript

Ruby and Python are both high-level, dynamically typed languages used for scripts and web backends. They differ in syntax and conventions: Python uses indentation to delimit blocks, while Ruby commonly uses the end keyword and also supports blocks enclosed in braces. Both can express object-oriented ideas. The better choice depends on your project, its libraries and the team maintaining it.

JavaScript is the language browsers execute to make webpages interactive. Ruby normally runs outside the browser, for example on a server or in a terminal. A Rails website may use Ruby on its server and JavaScript in its browser interface. Ruby is not a replacement for JavaScript in a normal webpage. Compared with languages that require more declarations or a separate compilation step, Ruby can be convenient for small scripts, while those languages may provide different compile-time checks or runtime characteristics.

LanguageTypical beginner useA useful distinction
RubyWrite a script, command-line tool or web backend.Ruby commonly runs on a computer or server, not directly in a webpage.
PythonWrite a script, automation tool or application.Indentation marks code blocks; its libraries and conventions differ from Ruby’s.
JavaScriptAdd browser interactivity or build a server with a JavaScript runtime.Browsers run JavaScript, while Ruby normally needs its own runtime.

What people build with Ruby

Web development and backend services: Ruby on Rails can route a request, load records and return HTML or JSON. A university booking site, for example, could use a Ruby backend to validate a reservation and store it. Rails supplies framework features; Ruby itself does not automatically provide a database or a web server.

Automation, scripting and command-line applications: a Ruby script can rename files, check a directory for missing documents or turn a repetitive report into a command a team can run. Ruby’s text and collection operations make small tools approachable. A command-line tool can grow to accept arguments and print helpful errors.

Data processing and development tooling: Ruby can read a CSV file, group records and produce a summary. Tools in the Ruby ecosystem use Ruby to manage builds, dependencies and other developer workflows. For large data sets, consider memory use and streaming rather than assuming the entire file belongs in an array.

Testing and prototyping: teams can use Ruby to express assertions about application behaviour and run automated test suites; RSpec is one testing tool in the ecosystem. A prototype might begin as a short script that proves a workflow before a team commits to a larger application. Whether Ruby is a good production choice still depends on deployment, performance and maintenance needs.

Advantages and limitations

Ruby’s readable syntax, consistent object model, expressive collections and established libraries can help people learn and build useful tools quickly. Rails provides a mature path for web applications. Ruby also has a community that maintains documentation, libraries and test tools. These strengths are valuable when the main cost is understanding and changing software over time.

There are tradeoffs. Dynamic typing does not catch every mismatch before code runs. Dependency versions and deployment environments need care. A Ruby implementation may not suit every CPU-heavy or memory-constrained workload without profiling and design changes. Browsers do not normally execute Ruby source, and Codectionary’s Playground currently edits Ruby but does not run it. Choose Ruby because it fits a task and a team, not because one language is universally best.

Read your first Ruby program

The example below turns a small list of learning tasks into numbered lines. First, tasks names an Array of three strings. The each_with_index method visits each string and gives the block both the task and its zero-based position. Adding one to the index turns positions 0, 1 and 2 into numbers a reader expects. String interpolation inserts those values into a double-quoted string. The puts method prints each completed line to the terminal.

Save the example as first_ruby.rb and run it with ruby first_ruby.rb after installing Ruby locally. The expected output has three lines: 1. Read a guide; 2. Try an example; 3. Build a small tool. Change one task, run it again and check what changed. Codectionary’s Playground can help you edit this example, but it cannot execute Ruby; use your local terminal or an official Ruby learning environment to see the output.

Terminal — after saving first_ruby.rb

ruby first_ruby.rb

A beginner’s path through the documentation

Start with variables and strings, then arrays and hashes, conditions, loops and methods. Practise by changing one example at a time and predicting its output. Once you can write a small script, learn how classes and modules organise a larger program. You do not need Rails to learn Ruby, and you do not need to memorise every syntax article before building something.

For a first independent project, make a terminal-based reading list: store titles in an array, print them with numbers and let yourself add a title. That project uses the same ideas as the example above while giving you a reason to learn input, methods and file storage later.

Syntax

name = "Sam"
puts "Hello, #{name}!"

Examples

Number a list of learning tasks

Run locally as first_ruby.rb. Expected output: three numbered tasks, one per line.

tasks = ["Read a guide", "Try an example", "Build a small tool"]

tasks.each_with_index do |task, index|
  puts "#{index + 1}. #{task}"
end
  1. The Array stores three strings in order under the name tasks.
  2. each_with_index runs the block once for each task and supplies its position, starting at zero.
  3. index + 1 makes the displayed numbering start at one; interpolation inserts the number and task into the string.
  4. puts prints each line. Edit a task or add a fourth item, then run the saved file again to check the output.

Ruby: background & uses

Used for
Rails web applications, Scripting, Prototypes
Created by
Yukihiro “Matz” Matsumoto
First released
1995 · first public release
Version / standard
Ruby 4.0

Current stable release line. Check framework compatibility before upgrading.

In the real world

  • GitHub: Its Ruby on Rails web application
  • Shopify: Its commerce platform with Rails
  • 37signals: Basecamp and other Rails products

Facts checked 8 September 2026. Product links describe documented uses.

Best practices

  • Run the saved .rb file with a local Ruby installation; the Codectionary Playground does not execute Ruby.
  • Change one example at a time and check the resulting output or error before moving on.
  • Choose clear names and test behaviour rather than assuming concise syntax guarantees correctness.

Runtime & versions

Ruby interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Ruby documentation

Specifications & further reading