fast-ruby icon indicating copy to clipboard operation
fast-ruby copied to clipboard

Method call in a block could compare to `&:method_name` too

Open arielj opened this issue 2 years ago • 1 comments

This test https://github.com/fastruby/fast-ruby/blob/master/code/general/block-apply-method.rb is comparing:

def fast
  [1, 2, 3].map { |n| do_something(n) }
end

def slow
  [1, 2, 3].map(&method(:do_something))
end

We could have one more test:

def other
  [1, 2, 3].map(&:do_something)
end

Also, I think the names fast and slow shouldn't be used for the methods, the names should describe what the method does, not which one is faster?

arielj avatar Jul 06 '22 15:07 arielj

@arielj I guess name fast and slow just indicate which way is faster. In this case if we should not use &method because its slower.

ashwinisukale avatar Oct 11 '22 11:10 ashwinisukale