Standard library and a short note on Rails
The libraries that ship with Ruby and cover most scripting needs, plus what Rails adds on top.
Standard library you will actually use
require "json"
require "csv"
require "set"
require "fileutils"
require "securerandom"
data = { name: "Ada", roles: ["admin", "editor"] }
json = JSON.generate(data)
parsed = JSON.parse(json, symbolize_names: true)
File.write("out.json", JSON.pretty_generate(parsed))
FileUtils.mkdir_p("tmp/reports")
CSV.foreach("rows.csv", headers: true) do |row|
puts row["email"]
end
ids = Set.new([1, 2, 2]) # => #<Set: {1, 2}>
token = SecureRandom.urlsafe_base64(32)
text = "the quick brown fox jumps"
puts text.scan(/\w+/).tally.sort_by { |_, n| -n }.first(3).inspect| Requirement | Library or method |
|---|---|
| Parse or emit JSON | json: JSON.parse, JSON.generate |
| CSV files | csv: CSV.foreach, CSV.read |
| Unique collections and fast membership | set, which Ruby 3 makes available without require |
| Files and directories | FileUtils, Pathname, Dir.glob |
| Random tokens and UUIDs | securerandom |
| Time zones | Time for basics, the tzinfo gem for real zone handling |
| HTTP requests | net/http in the standard library, faraday or httparty in practice |
A short note on Rails
Rails is a full framework built on Ruby: convention over configuration, MVC, and generators that write the boilerplate for you. Ruby is the language; Rails is a library you happen to load.
gem install rails
rails new blog
cd blog
bin/rails server
bin/rails generate model Post title:string body:text published_at:datetime
bin/rails generate controller Posts index show
bin/rails db:migrate# config/routes.rb
Rails.application.routes.draw do
resources :posts
root "posts#index"
end
# app/models/post.rb
class Post < ApplicationRecord
belongs_to :user
validates :title, presence: true, length: { maximum: 200 }
scope :published, -> { where.not(published_at: nil) }
end- Active Record maps a table to a class, so queries read as Ruby:
Post.published.order(created_at: :desc). - Convention replaces configuration:
Postmaps to thepoststable andPostsControllertoapp/controllers/posts_controller.rb. - Gems add authentication, background jobs and admin panels without wiring a stack from scratch, which is why Rails ships products quickly.
- Learn blocks, modules and the Enumerable methods first: most Rails magic is those three ideas used heavily.
💡
Sinatra is a good middle step: the same Ruby on the same Rack interface with a fraction of the framework. If Rails feels like more structure than a small service needs, use Sinatra or plain Rack first and grow into Rails later.
FAQ
Do I need Rails to write Ruby?
No. Ruby is widely used for scripts, CLIs, data pipelines and background workers, and many HTTP services use Sinatra or plain Rack instead of a full framework.
Why does my require fail for a gem in the Gemfile?
Run
bundle install first, then use bundle exec so the versions in Gemfile.lock are the ones loaded. Running from the project directory also matters.Related
Objects, modules and exceptions Syntax and blocks
Last refreshed 2026-09-18.