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 Memoizable | |
module ModuleMethods | |
def memoize | |
puts 'memoize' | |
end | |
end | |
def self.included(descendant) | |
descendant.extend(ModuleMethods) | |
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 Symbol | |
def & s | |
:"#{self} #{s}" | |
end | |
def to_proc | |
proc do |v| | |
to_s.split.inject(v){ |val, m| val.send(m) } | |
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
n = 1_000 | |
id = User.first.id | |
profile = User.only(:profile).find(id).profile | |
Benchmark.bm(50) do |x| | |
x.report('User.find(id).profile') do | |
n.times{ User.find(id).profile } | |
end |