
January 28, 2025
Ruby developers, let’s talk about something we all love: discovering a shiny gem of knowledge hidden in plain sight. Today, we’re not diving into RubyGems, but rather, the standard library—the treasure chest of tools that Ruby ships with. Some features are like diamonds on display (we all know and love Enumerable), but others? They’re like the cool secret room in your favorite video game—you have to know where to look.
Do you need more hands for your Ruby on Rails project?

1. ostruct — When You Want Objects Without the Hassle

If you’ve ever thought, “Why can’t objects behave more like hashes?” (and who hasn’t?), then meet OpenStruct. It lets you create objects with arbitrary attributes, no setup required.
require 'ostruct'
person = OpenStruct.new(name: "Ruby", favorite_language: "Ruby", coolness_level: 100)
puts "#{person.name}'s favorite language is #{person.favorite_language} with a coolness level of #{person.coolness_level}!"
Sure, it’s not the best fit for heavy-duty applications (hello, performance overhead), but for prototyping or lightweight use cases, OpenStruct is your bestie. Just don’t let your teammates catch you overusing it—you’ll never live it down.
2. date — Because Time Zones Are Scary Enough
Raise your hand if you’ve wrestled with time zones and barely survived. Now put that hand down and grab Ruby’s date library instead. While not as fancy as ActiveSupport::TimeWithZone, it’s simple and effective for managing dates without dragging the whole Rails framework into your project.

require 'date'
birthday = Date.new(1995, 12, 25)
puts "You were born on a #{birthday.strftime('%A')}, how cool is that?"
Pro tip: Combine it with the time library for some truly heroic feats of temporal manipulation.
3. delegate — Work Smarter, Not Harder
Delegation is a common pattern in programming, and Ruby makes it ridiculously easy with the delegate library. It’s like having a personal assistant for your objects. Just don’t start delegating your own tasks—it’s called procrastination, and there’s no require ‘motivation’ in Ruby.
require 'delegate'
class Stats < SimpleDelegator
def average
sum.to_f / size
end
end
stats = Stats.new([10, 20, 30])
puts "The average is #{stats.average}!"
4. forwardable — Delegation’s Sassy Sibling
If you like delegate but want more control, check out forwardable. It’s lightweight and great for selectively forwarding methods to another object. Think of it as the minimalist’s delegation tool.
require 'forwardable'
class Chef
extend Forwardable
def_delegators :@oven, :bake, :preheat
def initialize(oven)
@oven = oven
end
end
The forwardable library is perfect when you’re channeling your inner Ruby purist.
5. set — For the Times You’re Over Arrays
Sure, arrays are great, but sometimes you want unique elements and blazing-fast lookups. Enter Set. It’s a powerful alternative that behaves more like the data structure you learned about in CompSci 101.
require 'set' languages = Set.new(["Ruby", "Python", "JavaScript", "Ruby"]) puts languages.to_a # ["Ruby", "Python", "JavaScript"]
No duplicates? No problem. Just don’t try to feed it to your Rails app without some extra care.
Wrapping It Up
Ruby’s standard library is filled with delightful tools that can make your life as a developer easier—and maybe even save you a dependency or two. So next time you’re about to reach for a gem, take a moment to dig into Ruby’s treasure trove. Who knows? You might just strike gold.
Or, at the very least, you’ll impress your coworkers by casually dropping “Oh, I just used Set for that” into your next standup. And isn’t that what really matters?
