Skip to content

Instantly share code, notes, and snippets.

View bartoszkopinski's full-sized avatar
:octocat:
Coding...

Bart bartoszkopinski

:octocat:
Coding...
View GitHub Profile
module Memoizable
module ModuleMethods
def memoize
puts 'memoize'
end
end
def self.included(descendant)
descendant.extend(ModuleMethods)
end
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
@bartoszkopinski
bartoszkopinski / find_vs_where_benchmark.rb
Last active May 8, 2016 23:59
Mongoid benchmark, #find vs. #where, #only vs. no #only
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