Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arielj opened this issue Jul 6, 2022 · 1 comment
Open

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

arielj opened this issue Jul 6, 2022 · 1 comment

Comments

@arielj
Copy link
Collaborator

arielj commented Jul 6, 2022

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?

@ashwinisukale
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants