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 Account | |
def initialize | |
@members = [] | |
end | |
def add_member(m) | |
@members << m | |
end | |
def has_member?(m) |
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
ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES << "X" | |
class FooParser | |
def self.from_tabs(stream) | |
stream.each do |line| | |
while line.split("\t").size < FIELDS.size do | |
line += stream.readline | |
end | |
parts = line.split "\t" | |
next if parts.all? {|p| p.to_s.strip.blank?} |
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 'rubygems' | |
require 'spec' | |
class MyExampleGroup < Spec::Example::ExampleGroup | |
before(:each) do | |
puts "in before(:each)" | |
my_custom_method | |
end | |
def my_custom_method |
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
# The goal is to make classes who include Foo also get the methods | |
# from Bar, but after Foo has already been included | |
module Foo | |
def foo; end | |
end | |
class FooBar | |
include Foo | |
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
# The goal is to make classes who include Foo also get the methods | |
# from Bar, but after Foo has already been included | |
module Foo | |
def foo; end | |
end | |
class FooBar | |
include Foo | |
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
class Cart < ActiveRecord::Base | |
has_many :items | |
alias_method :items_proxy, :items | |
def add_item(options) | |
item = items_proxy.build options | |
if item.valid? | |
item | |
else | |
items_proxy.delete item |
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
module Muahaha | |
def self.included(target) | |
target.class_eval do | |
instance_methods.each do |m| | |
next if m.to_s.include?("__") || m.to_s == "send" | |
alias_method "old_#{m}", m | |
eval <<-END | |
def #{m}(*args, &block) | |
return if rand > 0.95 | |
send("old_#{m}", *args, &block) |
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 SimpleAR | |
def self.has_many(collection) | |
define_method(collection) do | |
var_name = "@#{collection}" | |
instance_variable_set(var_name, []) unless instance_variables.include?(var_name) | |
instance_variable_get var_name | |
end | |
end | |
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
# This comes from GenericWebLibrary | |
class BaseComponent | |
end | |
# This comes from RestExtensionLibrary | |
class RestComponent < BaseComponent | |
end | |
# In a language with mixins you could do | |
module SomeFilterStuff |
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
describe Agency do | |
before(:each) do | |
puts "in before(:each)" | |
end | |
after(:each) do | |
puts "in after(:each)" | |
end | |
before(:all) do |