Skip to content

Instantly share code, notes, and snippets.

@Jacobkg
Jacobkg / main.rb
Created January 12, 2015 23:38
Celluloid Thread.current
require 'celluloid/autostart'
class ExceptionHandler
def self.notify(e)
puts "Something has gone wrong" unless Thread.current[:context]
end
end
@Jacobkg
Jacobkg / gist:3037786
Created July 3, 2012 05:00
Trying to respect the law of demeter
class User < ActiveRecord::Base
belongs_to :account
#A number of methods giving this class too many responsibilities already
end
class Account < ActiveRecord::Base
# t.integer credits
def add_credit(amount)
@Jacobkg
Jacobkg / gist:2017761
Created March 11, 2012 19:23
For when you want to stub class methods on a class that may or may not be loaded
class SuperStubbedClass; end
class ClassStubber
def self.stub!(class_string)
classes = class_string.split('::')
parent_klass = Object
classes.each do |class_name|
define_if_not_already(class_name, parent_klass)
parent_klass = parent_klass.const_get(class_name)
end