Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created January 21, 2016 22:54
Show Gist options
  • Save kenmazaika/a66dec3366f0dde29f1d to your computer and use it in GitHub Desktop.
Save kenmazaika/a66dec3366f0dde29f1d to your computer and use it in GitHub Desktop.
require 'benchmark'
class Dog
def say(*words)
puts 'Doggie says: ' + words.slice(1, words.length - 1).join(' ')
end
def method_missing(method, *args, &block)
if /^say_\B/ =~ method.to_s
words = method.to_s.split('_')
say(*words)
end
end
end
Benchmark.bm(7) do |x|
x.report { (1..100000).each { |x| Dog.new.say_woof! } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment