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 Foo | |
def value | |
"Value" | |
end | |
def eval_stuff | |
instance_eval &(Proc.new { puts value }) | |
instance_eval &(Proc.new {|foo| puts foo.value }) | |
instance_eval &(lambda {|x| puts x.value }) | |
instance_eval &(lambda {|x| puts value }) |
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
describe "let behavior" do | |
foo = "original recipe" | |
let(:foo) { "extra crispy" } | |
specify { foo.should == "extra crispy" } | |
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
require 'active_support/core_ext/array' | |
class FactoryGirl | |
attr_accessor :options | |
def self.create(model, options = {}) | |
new(model, options) | |
end | |
def initialize(model, options) |
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
def let(name, &block) | |
define_method(name) do | |
__memoized.fetch(name) {|k| __memoized[k] = instance_eval(&block) } | |
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
require 'active_support/core_ext/array' | |
class FactoryGirl | |
attr_accessor :options | |
def self.create(model, options = {}) | |
new(model, options) | |
end | |
def initialize(model, options) |
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 ActiveSupport | |
module FastSafeBuffer | |
[ | |
:capitalize, :chomp, :chop, :delete, :downcase, :gsub, :lstrip, | |
:next, :reverse, :rstrip, :slice, :squeeze, :strip, :sub, | |
:succ, :swapcase, :tr, :tr_s, :upcase, :prepend | |
].each do |unsafe_method| | |
if String.new.respond_to? unsafe_method | |
module_eval <<-EVAL | |
def #{unsafe_method}!(*) |
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
## Decorating | |
chris@luna /var/www/rails3-follow git:(master*) ruby-1.9.3 % rails r bench.rb | |
{:count=>39, :heap_used=>2169, :heap_length=>2444, :heap_increment=>0, :heap_live_num=>498236, :heap_free_num=>378418, :heap_final_num=>9986} | |
user system total real | |
Extend 0.820000 0.040000 0.860000 ( 0.868023) | |
{:count=>39, :heap_used=>6147, :heap_length=>7027, :heap_increment=>880, :heap_live_num=>498236, :heap_free_num=>2004679, :heap_final_num=>0} | |
## Extending | |
chris@luna /var/www/rails3-follow git:(master*) ruby-1.9.3 % rails r bench.rb | |
{:count=>39, :heap_used=>2169, :heap_length=>2444, :heap_increment=>0, :heap_live_num=>498514, :heap_free_num=>378128, :heap_final_num=>9986} |
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 Question < ActiveRecord::Base | |
belongs_to :survey | |
def samples | |
populate_samples | |
end | |
private | |
def populate_samples |
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
$__load_path_size = nil | |
$__cached_load_paths = {} | |
$__cache_scanned = {} | |
PATH_START_SLASH = "/" | |
PATH_START_PERIOD = "." | |
PATH_START_TILDE = "~" | |
::Kernel.class_eval do | |
alias __gem_original_require gem_original_require |
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
Submission.from_upload(user, upload).tap do |s| | |
add_submission s | |
publish 'submission.uploaded', s.to_hash | |
end |