Ruby’s stdlib never ceases to amaze. If you’re making a CLI tool in Ruby, your efforts are made more straightforward by the existence of the OptionParser class. Use it, and let happiness fill your heart.
Rack apps are generally straightforward to test because of their very basic public interface. But where do we put specific things, in this case, a cookie for the request, on that
env argument it takes? Here’s one way.
Kaminari provides easy pagination in a rails app. It’s great to use. We’ll make it better by adding a little function to your controllers to provide useful pagination headers.
The default serialization of error states in Rails might not be what you want for your app. In that case, it’d be worth knowing how to write a custom serialization format for your needs. In my case, I am trying to match the JSON API format for errors. Here’s a potential implementation…
Rails 4 introduced the pattern of strong parameters at the controller layer. As a best practice, you will explicitly list the parameters that an endpoint should accept in payloads. Arrays are specified just slightly different.
In Ruby, it’s common to see new methods defined dynamically or on the fly for your class. And who doesn’t want to have a piece of that metaprogramming?
I love Ruby’s syntax for method calls. The syntax for calling dynamic methods is pretty nice, and it’s easily mastered.
Exercism.io is a fantastic site and tool that provides a wealth of daily code exercises. If you want to learn to be better in a language, it’s a great resource to do exercises and receive feedback.
Have you ever wished you could save a gem to your
Gemfile straight from the command line? I wish Rubygems had this built in, but it’s easy to add. After all, there’s a gem for that.
Interactive debugging can sometimes be faster and more effective in helping you code than a
puts statement. It’s easy to get interactive debugging in Ruby or on Rails with the help of a nice gem.