Let's start with wtf!?
Published almost 6 years ago
UPDATE : Check Ticket 8818
Welcome to my new blog :) Now over to rails..
So you’ve been told about using cute shortcuts for enumerator like Post.find(:all).map(&:title) – you feel great using it, don’t you ?? And you laughed at those who didn’t understand how &:sym worked and continued to use .map ( |shit| shit.stupid } syntaxt! You were made feel geeky indirectly. I was there :-)
I’d let benchmark speak for me..
require 'benchmark' class Symbol def to_proc Proc.new { |*args| args.shift.__send__(self, *args) } end end n = 10000 s = Struct.new :id messages = [] n.times { messages << s.new(:id => rand(n)) } Benchmark.bm do |x| # Integer x.report { n.times { messages.map{|m| m.id} } } x.report { n.times { messages.map(&:id) } } end # $ ruby perform.rb # user system total real # 33.280000 0.860000 34.140000 ( 34.912584) # 191.940000 1.660000 193.600000 (197.168849)
Need I say anymore ? Wake up and smell the coffee.