Skip to content

Best Gems for Ruby

Samuel Kerr edited this page Aug 31, 2016 · 1 revision

If you do decide to stay and work on Ruby things I recommend you immediately audit your Gemfile and try to remove 75% of all your dependencies. In my experience I've only needed a few gems across all projects over the past ~4 years. Here's pretty much all you need to get 99% of the way.

All of these library are specifically chosen because:

They have minimal to zero dependencies Their transitive dependencies are acceptable They do what they say on the box Easy to work with & build more complex functionality on top of Well maintained So here we go!

delegate - DelegateClass is the shit. forwardable - def_delegators makes composition easy. No dependencies required json - Standard library is where it's at time - Time#iso8601 logger - Logger.new($stdout). Have never seen a use case where something more "powerful" than the standard library logger is not enough. set - Fundamental data type that's nice to work with securerandom - SecureRandom#uuid & SecureRandom#hex are useful in many situtations minitest - Bow Before Minitest concord - I cannot live without this. Dead simple composition without the boiler plate lift - Hash initializer + block form. Remarkably simple and effective way to remove duplicating this hundreds of times. faraday - If you need an HTTP client this is it. Minimal dependencies and makes net/http useful. statsd-ruby - Minimal, no dependencies, no problems redis - Official and best redis driver mongo - Official and fully featured mongo driver sequel - Hands down the best SQL library (& minimal active record pattern based ORM) the ecosystem has to offer connection_pool - Fantastic connection pool library with no dependencies and does exactly what you expect: create thread-safe connection pools. sidekiq - The best job queueing system Ruby has to offer. webmock - Sometimes you need this sort of thing. Don't waste your time with anything else. Webmock does everything I've ever needed and will probably for you too. rack-test - If you need to test rack apps this is the only way to do it. mustache - Only sane way to do any kind of templating. I use ERB when I don't care about maintainability. puma - Pretty damn good threaded rack server. Honorable mentions:

Virtus - For when you need type coercions. I don't use this in new code anymore. This only useful when you're dealing with random untyped garbage input. ROM - I respect the hell out of @solnic (he falls in the well respected author list) for all his work on this but I can't put it in the must have list. In general a data mapper is powerful abstraction that fits niceley between things like a row data gateway, active record, or a repository. I encourage you to look at this library but don't shy away from writing an application specific persistence layer. It's easier than you think using the low level libraries like Sequel or a raw DB driver. factory_girl - Many projects need factories, and not just for persisted objects! Unfortunately I cannot recommend factory girl globally because it depends on the mother of all transitive dependencies: ActiveSupport. However it's by far and away the best factory library out there. I do not recommend fabrication because it uses instance_eval in the public API. FactoryGirl uses instance eval for definitions but not in the public API. sinatra - I like sinatra but think there may be something better at this point. I mainly stick with Sinatra because you can learn everyting in a short time and in generally solves most of the problem: map complicated path to code block. Beware of libraries monkey patching it though. Building large sinatra applications can be a bit weird but doable. Pairs very nicely with mustache-sinatra.