View shrine_storage.rb
# This sets up both a memory store and file system store for Shrine file uploads.
# We use the memory store by default but in cases where you want to test actual
# file uploads you can enable it with `file_upload: true` on a per example basis
require "shrine/storage/memory"
require "shrine/storage/file_system"
# We use a delegator to swap out the storage dynamically
# since the storage hash is duplicated for each uploader
class Shrine::Storage::Dynamic < SimpleDelegator
def initialize(initial, storages)
View episode_search.rb
class EpisodeSearch
attr_reader :ability, :options
delegate :sanitize, to: Episode
def initialize(ability, options = {})
@ability = ability
@options = options.dup
def tag
cd ~/code/rails
railties/bin/rails new ~/code/hello --edge
cd ~/code/hello
echo "gem 'puma'" >> Gemfile
rails g controller hello index
# fill controller
# separate tab
curl localhost:9292/hello/index


I took the ideas presented here and built a gem called Mustard. Check it out!

There are several expectation/assertion interfaces available for writing tests/specs. Here are some issues I have with them.


  • The order of assert_equals feels backwards
  • Oh wait, that should be assert_equal (that too)

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
View development.rb
class AssetHeaders
def initialize(app)
@app = app
def call(env)
request =
response =
if request.path =~ /^\/assets\//
# there maybe a better way to add headers
View tasks_controller_refactoring.rb
class TasksController < ApplicationController
def update
tracker =
if @task.update_attributes(params[:task]), socket_id).push_changes, current_user).deliver_email
# success response
# failure respond
View abilities.rb
module Abilities
def self.ability_for(user)
if user.admin?
else user
View RailsCasts.tmtheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
View Default.sublime-keymap
{ "keys": ["ctrl+shift+."], "command": "erb" },
{ "keys": ["ctrl+shift+,"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } },
{ "keys": ["ctrl+super+r"], "command": "reveal_in_side_bar" }