Andy Croll·Mar 16, 2018Enumerable avoids using temporary variables when loopingSome of my favourite Ruby features are to be found in the Enumerable module. You can read more about it in the Ruby documentation.
Andy Croll·Mar 16, 2018Be sparing when using unlessOne of Ruby’s strengths is its delightful, built-in syntactic sugar. One example of this is the keyword unless, which you can use in place…
Andy Croll·Mar 16, 2018Truthiness in ConditionalsRuby’s conditional syntax is ‘truthy’, meaning that any statement in a conditional that evaluates to nil is considered to be equivalent to…
Andy Croll·Mar 4, 2018Set your page title in the view template using content_forRails uses content_for as its primary way to store content in one place for use in other views, layouts or helpers. Find out more about…
Andy Croll·Mar 4, 2018Choose UUIDs for model IDs in RailsA universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. Sometimes it is referred to as…A response icon2A response icon2
Andy Croll·Mar 4, 2018Use a pull request templateIf you’re submitting work for review, pull requests are a great way to group related changes and discuss approaches and improvements. The…
Andy Croll·Jan 21, 2018Extract conditionals into well-named methodsOne of the simplest (and most effective) ways to refactor is to extract a method. The naming of an extracted method is a great tool for…
Andy Croll·Jan 15, 2018Use simplecov in your Rails test suiteA useful way of assessing the effectiveness of your testing is to use the simplecov gem with your Rails application. It counts the number…
Andy Croll·Jan 2, 2018Rescue specific errors. Avoid rescuing StandardError. Don’t rescue Exception.There are many built-in error classes in Ruby and Rails. Most of these errors are subclasses of Ruby’s StandardError. You can find more…
Andy Croll·Jan 2, 2018Don’t use default_scope. Ever.When you would like a scope to be applied across all queries on a model, you can use default_scope. See more in the ActiveRecord Query…