This file contains hidden or 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 ActiveRecord::Associations::Builder | |
class HasAndBelongsToMany < CollectionAssociation #:nodoc: | |
def define_destroy_hook | |
name = self.name | |
model.send(:include, Module.new { | |
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | |
def destroy_associations | |
association(#{name.to_sym.inspect}).delete_all_on_destroy | |
super | |
end |
This file contains hidden or 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
internet () { | |
if ( | |
ping -c 3 -t 3 google.com > /dev/null 2>&1 | |
) | |
then | |
echo 'yep' | |
else | |
echo 'nope' | |
fi | |
} |
This file contains hidden or 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 Foobar | |
def self.included(klass) | |
klass.instance_eval do | |
state_machine :foo, :initial => :bar do | |
# etc etc etc | |
end | |
end | |
end |
This file contains hidden or 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
# config/initializers/activity_order.rb | |
ACTIVITIES = [PersonalValues, PersonActions, SomeOther] | |
# config/initializer/array.rb | |
class Array | |
def relative_index(item, idx) | |
self[index(item) + idx] | |
end | |
def next(item) |
This file contains hidden or 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
Actions = [PersonalValues, PersonActions, SomeOther] | |
Locations = [first_action_path, second_action_path, third_action_path] | |
def next_activity(thing) | |
Locations[Actions.index(thing.class) + 1] | |
end | |
def prev_activity(thing) | |
Locations[Actions.index(thing.class) - 1] | |
end |
This file contains hidden or 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
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
end | |
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
end |
This file contains hidden or 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 Person < ActiveRecord::Base | |
validates :name, :presence: true, :if: :authed? | |
validates :name, :presence: true, :if: :unaccepted? | |
validates :name, :presence: true, :if: :accepted? | |
state_machine :state, :initial => :authed do | |
event :filled_out_profile do | |
transition :authed => :unaccepted | |
end |
This file contains hidden or 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 SuperClass | |
def some_method | |
puts "foo" | |
end | |
end | |
class BabyClass << SuperClass | |
def some_method | |
super | |
puts "bar" |
This file contains hidden or 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
$.extend(Array.prototype, { | |
inject: function(aggregate, iterator) { | |
$(this).each(function() { | |
aggregate = iterator(aggregate, this); | |
}); | |
return aggregate; | |
}, | |
sum: function() { | |
return this.inject(0, function(aggregate, item) { |
This file contains hidden or 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 | |
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} | |
require 'rubygems' unless ENV['NO_RUBYGEMS'] | |
else | |
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
end | |
require 'spec/autorun' |