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

Open
#201 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
performance

Research direction

Start with code/general/block-apply-method.rb and inspect how its existing comparisons are structured. Add the &:do_something case and rename fast and slow to names describing their behavior. Done means the file contains all three comparable forms with descriptive method names and its existing benchmark or test still runs.

Written by the indexing model from the issue text.

Description

Suggestion

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?

Dominant language
Ruby
Stars
5.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fastruby/fast-ruby

All issues in fastruby/fast-ruby

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.