Ruby Style Guide

Ruby is the main language at Shopify. We are primarily a Ruby shop and we are probably one of the largest out there. Ruby is the go-to language for new web projects and scripting.

We expect all developers at Shopify to have at least a passing understanding of Ruby. It’s a great language. It will make you a better developer no matter what you work in day to day. What follows is a loose coding style to follow while developing in Ruby.

This Style Guide is the result of over a decade of Ruby development at Shopify. Much of its content is based on Bozhidar Batsov’s Ruby Style Guide, adapted to Shopify by many contributors.

Adoption with RuboCop

We recommend using RuboCop in your Ruby projects to help you adopt this Style Guide. To know how to install and use RuboCop please refer to RuboCop’s official documentation.

We offer a default RuboCop configuration you can inherit from and be in sync with this Style Guide. To use it, you can add this to your Gemfile:

  gem 'rubocop-shopify', require: false

And add to the top of your project’s RuboCop configuration file:

  inherit_gem:
    rubocop-shopify: rubocop.yml

For more information about inheriting configuration from a gem please check RuboCop’s documentation.

Table of Contents

General

Formatting

Syntax

Naming

Comments

Classes and Modules

Exceptions

Collections

Strings

Regular Expressions

Percent Literals

Testing