Skip to content

Instantly share code, notes, and snippets.

View patmaddox's full-sized avatar
🤔
Trying to figure out how to look up comments I've left

Pat Maddox patmaddox

🤔
Trying to figure out how to look up comments I've left
View GitHub Profile
class Account
def initialize
@members = []
end
def add_member(m)
@members << m
end
def has_member?(m)
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?}
require 'rubygems'
require 'spec'
class MyExampleGroup < Spec::Example::ExampleGroup
before(:each) do
puts "in before(:each)"
my_custom_method
end
def my_custom_method
# 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
# 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
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
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)
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 comes from GenericWebLibrary
class BaseComponent
end
# This comes from RestExtensionLibrary
class RestComponent < BaseComponent
end
# In a language with mixins you could do
module SomeFilterStuff
describe Agency do
before(:each) do
puts "in before(:each)"
end
after(:each) do
puts "in after(:each)"
end
before(:all) do