- Your class can be no longer than a hundred lines of code.
- Your methods can be no longer than five lines of code
- You can pass no more than four parameters and you can't just make it one big hash.
- In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
- Your view can only know about one instance variable.
- Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
- Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
include Open3 | |
skip_erb_files = true | |
compiler_ruby = `which rbx`.strip | |
compiler_ruby = `which ruby`.strip if compiler_ruby.length == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encodes a string from encoding "from" to encoding "to" in | |
# a way that works for both ruby 1.8 and 1.9 | |
def convert_string_encoding(to, from, str) | |
if "1.9".respond_to?(:force_encoding) | |
str = str.dup if str.frozen? | |
str.encode(to, from, :undef => :replace) | |
else | |
require 'iconv' | |
Iconv.conv(to, from, str) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# code from: http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 | |
# and also: https://gist.github.com/1976864 | |
# Serialized columns in AR don't support UTF-8 well, so set the encoding on those | |
class ActiveRecord::Base | |
def unserialize_attribute_with_utf8(attr_name) | |
traverse = lambda do |object, block| | |
if object.kind_of?(Hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cocktail | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def liquor | |
case self.name | |
when "journalist": "gin" | |
when "sazerac": "whiskey" |
Let's have some command-line fun with curl, [jq][1], and the [new GitHub Search API][2].
Today we're looking for:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'cinch', '< 1.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
class FakeGitHub < Sinatra::Base | |
def simulate_error! | |
@@simulate_error = true | |
end | |
def reset! | |
@@simulate_error = false | |
end |