.rb File Extension
.rb file contains, how to open and run Ruby source code, how Poly supports it, and how it differs from related Ruby project files. File extension details for .rb
Full Support| File type | Ruby source code |
|---|---|
| MIME type | |
| Encoding | Unicode plain text, UTF-8 by default in current Ruby |
| Operating systems | Windows, macOS, Linux |
| Opens with | Visual Studio Code, RubyMine, Vim or Neovim, Any text editor |
| Poly support | Yes. Poly recognizes .rb as readable Ruby source code. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. Ruby source opens in Poly's code editor with syntax highlighting. |
| Poly agent | Yes. The Poly agent can read and reason about the source text. |
What kind of file is a .rb?
A .rb file contains source code for the Ruby programming language. It is editable text, not a compiled executable. A file can be a standalone script, a library loaded by another program, or one part of an application such as a Ruby on Rails project. Ruby's loader treats the .rb suffix as a source file and can also try that suffix when require is given a feature name without one.1
Ruby source has no fixed magic bytes. A first line such as #!/usr/bin/env ruby is a useful clue for an executable script, but many libraries omit it. Current Ruby uses UTF-8 as the default script encoding. A magic comment on the first line, or the second line after a shebang, can declare another encoding.2
IANA does not register a Ruby-specific media type. Some tools use unregistered labels such as text/x-ruby or application/x-ruby, while Poly classifies .rb as readable text/plain.3
.rb does not translate it into Ruby or prove that it is valid source. Inspect unfamiliar code before running it.How do I open a .rb on my computer?
Any text editor can open .rb files on Windows, macOS, or Linux. Visual Studio Code, RubyMine, Vim, Neovim, and other Ruby-aware editors add syntax highlighting, navigation, formatting, tests, and debugging. Ruby's official documentation recommends an editor or IDE with language support for more effective coding.4
Install a Ruby interpreter when you need to check or run the source:
ruby -c example.rb
ruby example.rb
The first command checks syntax without executing the program. The second runs it.5 A project may also depend on gems listed in a Gemfile, so follow its setup instructions. Opening source as text is safe, but running it can execute arbitrary code, access files or networks, and install or load dependencies.
Poly support for .rb
Poly opens .rb files in a code-friendly viewer with Ruby syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search, so you can find a class by name or search for code by its likely purpose. The Poly agent can summarize a script, explain methods, and help trace likely behavior.
Poly does not execute Ruby, install gems, expand metaprogramming, or reproduce a running application's state. Keep related source, tests, a Gemfile, lockfile, and documentation together when project context matters.
History of .rb
Yukihiro “Matz” Matsumoto began Ruby on February 24, 1993. Ruby was publicly released in 1995.6 The short .rb suffix became the conventional name for loadable Ruby source and remains visible throughout the standard library.
The language name was inspired by Perl. Matsumoto chose another jewel name, then noted that ruby follows pearl in both birthstones and traditional font sizes.6
Working with .rb and related files
Ruby projects use several filename conventions:
| File or suffix | Typical role |
|---|---|
.rb | Ordinary Ruby source or script |
Gemfile | Gem dependency declarations written in Ruby syntax |
Rakefile or .rake | Tasks interpreted by Rake |
.gemspec | Ruby code describing a gem package |
.erb | Text template containing embedded Ruby expressions |
These files may contain Ruby syntax, but changing their names can change how tools discover or interpret them. Keep .rb source in version control, use ruby -c for a quick syntax check, and use the project's own test command before distributing changes. Export to plain text only when the receiver needs to read the code without Ruby-specific tooling.
Footnotes
- Ruby. Loading Features. Documents
.rbas the suffix for source files loaded by Ruby. ↩ - Ruby. Encodings. Documents UTF-8 as the default script encoding and the source-file magic comment. ↩
- Internet Assigned Numbers Authority. Media Types Registry. The registry has no Ruby-specific media type. ↩
- Ruby. Documentation: Editors and IDEs. ↩
- Ruby. Ruby Command-Line Options. Documents
-cas a syntax check that does not execute the program. ↩ - Ruby. Official Ruby FAQ: Ruby's History and Name. Ruby's About Ruby records the 1995 public release. ↩ ↩2