Ruby: Standard Library, Gems & Tooling
Standard Library Highlights
require 'json'
JSON.parse('{"name": "Alice"}') # => {"name" => "Alice"}
{ name: "Alice" }.to_json # => '{"name":"Alice"}'
require 'date'
Date.today # #<Date: 2026-05-07>
Date.parse("2026-01-15")
DateTime.now
Time.now.strftime("%Y-%m-%d %H:%M")
require 'net/http'
require 'uri'
uri = URI('https://api.example.com/users')
response = Net::HTTP.get_response(uri)
JSON.parse(response.body)
require 'fileutils'
FileUtils.mkdir_p('path/to/dir')
FileUtils.cp('src.txt', 'dst.txt')
FileUtils.rm_rf('temp/')
require 'erb'
template = ERB.new("Hello, <%= name %>!")
template.result(binding) # "Hello, Alice!" (uses local binding)
require 'digest'
Digest::SHA256.hexdigest("password")
Digest::MD5.hexdigest("data")Gems & Bundler
# Gemfile
source "https://rubygems.org"
ruby "3.3.0"
gem "rails", "~> 7.2" # ~> means >= 7.2, < 8.0
gem "pg" # PostgreSQL adapter
gem "puma" # Web server
gem "sidekiq" # Background jobs
group :development, :test do
gem "rspec-rails"
gem "factory_bot_rails"
end
group :test do
gem "faker"
gem "shoulda-matchers"
end
# Bundler commands
bundle install # install gems from Gemfile
bundle update rails # update specific gem
bundle exec rspec # run command in bundle context
bundle exec rake db:migrate
gem install bundler # install bundler itself
gem list # list installed gemsRSpec Testing
# spec/models/user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
let(:user) { build(:user) } # FactoryBot
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_uniqueness_of(:email) }
end
describe '#full_name' do
it 'combines first and last name' do
user = described_class.new(first_name: 'Alice', last_name: 'Smith')
expect(user.full_name).to eq('Alice Smith')
end
end
context 'when admin' do
let(:admin) { create(:user, :admin) }
it 'can access admin panel' do
expect(admin.can?(:access, :admin_panel)).to be true
end
end
endVersion Management & Tooling
# rbenv (recommended version manager)
rbenv install 3.3.2
rbenv global 3.3.2
rbenv local 3.2.0 # .ruby-version in project dir
# RVM (alternative)
rvm install 3.3.2
rvm use 3.3.2 --default
# Common tools
gem install solargraph # LSP for IDE support
gem install rubocop # linter/formatter
gem install brakeman # security scanner
gem install pry # better REPL than irb
# Interactive Ruby
irb # built-in REPL
pry # enhanced REPL with debugging
# Rake tasks
rake -T # list all tasks
rake db:migrate
rake testKeep your own version of these notes — editable, searchable, and organised by your stack.
Start free