What is the RB file format?
.rb files are associated with the Ruby programming language. Files with the .rb extension contain source code written in Ruby - an interpreted, object-oriented scripting language created by Yukihiro "Matz" Matsumoto. .rb files can be edited in any plain-text editor. In order to run .rb programs, a Ruby environment must be installed; scripts are typically executed with the ruby filename.rb command.
Ruby has developed into a very popular programming language with a rich ecosystem and strong community support. Its main features are simplicity, expressive syntax, and multi-platform support across Windows, macOS and Linux. Ruby is available under an open-source licence (Ruby Licence and BSD 2-Clause) - not a copyleft licence. Ruby is consistently ranked among the widely used programming languages worldwide and is frequently recommended as a first programming language for beginners.
.rb is the canonical source unit for standalone scripts, Ruby on Rails web applications, and libraries distributed as .gem packages. Related formats that share Ruby syntax include .erb embedded template files and .rake build scripts.
Security & safety
RISK: MEDIUMA .rb file is source code: opening it in a text editor or viewer is completely safe. The risk is in RUNNING it - "ruby file.rb" executes whatever the script contains, including file deletion, network calls, or installing software. Never run a Ruby script from an untrusted source without reading it first. Be wary of scripts that shell out (system/backticks/exec), download code at runtime, or require unknown gems. Reading the plain text before execution is the safe approach.
Format details
in a nutshellPrograms that open RB files
Technical details
deep spec| MIME type | application/x-ruby; also registered as text/x-ruby and text/x-ruby-script |
| File encoding | UTF-8 plain text (default since Ruby 2.0; earlier versions required `# encoding: utf-8` on line 1 or 2 for non-ASCII source) |
| Magic bytes / signature | None - plain text with no fixed byte signature; executable scripts typically begin with a shebang line (`#!/usr/bin/env ruby`) |
| Interpreter command | `ruby filename.rb` at the command line; Windows users typically invoke `ruby.exe` via RubyInstaller |
| Frozen-string pragma | `# frozen_string_literal: true` on line 1 makes all string literals immutable at runtime, improving performance (available since Ruby 2.3) |
| Syntax versioning | No file-level version field; syntax compatibility is governed by the interpreter version (1.8, 1.9, 2.x, 3.x) |
| Encoding declaration | Optional magic comment `# encoding: <name>` (or `# coding: <name>`) on line 1 or 2; mandatory for non-ASCII source on Ruby < 2.0 |
| Typical file size | 1 KB - 100 KB; most application files fall in the 2-30 KB range |
| Internal structure | Sequential Ruby statements - require/load calls, class and module definitions, method (def) bodies, expressions; executed top-to-bottom by the interpreter |
| Related extensions | `.rbw` (Windows silent-mode, no console), `.gemspec`, `.rake`, `.ru` (Rack config), `.erb` (embedded Ruby template) |
| Platform support | Cross-platform: Windows, macOS, Linux, BSD, and any OS with a Ruby interpreter (MRI/CRuby, JRuby, TruffleRuby) |
| Primary use cases | Standalone automation scripts, Ruby on Rails controllers and models, RubyGems library source, Rakefiles (build tasks), Vagrantfiles, and Homebrew formulae |
| Released | 1995 (Ruby 0.95 public release; Ruby 1.0 in December 1996) |
| Latest version | Tracks the Ruby language; Ruby 3.4 (December 2024). Source files are version-agnostic text. |
| Open standard | Yes · royalty-free |
| Specification | www.ruby-lang.org |
RB conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about RB files.