rubocop / rubocop/ruby-style-guide
Single- vs multiline lambdas
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
The style guide currently says
Use the new lambda literal syntax for single line body blocks. Use the lambda method for multi-line blocks. [link]
# bad l = lambda { |a, b| a + b } l.call(1, 2) # correct, but looks extremely awkward l = ->(a, b) do tmp = a * 7 tmp * b / 50 end # good l = ->(a, b) { a + b } l.call(1, 2) l = lambda do |a, b| tmp = a * 7 tmp * b / 50 end
I disagree. Having to change lambda syntax from -> {} to lambda do; end when a lambda grows too large for one line seems wrong. For multi-line lambdas, I would prefer using the stabby lambda syntax with a curly-brace block:
# good
l = ->(a, b) {
tmp = a * 7
tmp * b / 50
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the current style-guide guidance quoted in the issue and the nine-comment discussion to understand the unresolved positions. Done means reaching a decision on multiline stabby-lambda syntax and updating the relevant guidance and examples consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100