Skip to content

Files

Latest commit

 

History

History
31 lines (22 loc) · 643 Bytes

Style-RedundantFetchBlock.md

File metadata and controls

31 lines (22 loc) · 643 Bytes

Pattern: Redundant fetch block

Issue: -

Description

Identifies places where fetch(key) { value } can be replaced by fetch(key, value).

In such cases fetch(key, value) method is faster than fetch(key) { value }.

Examples

# bad
hash.fetch(:key) { 5 }
hash.fetch(:key) { true }
hash.fetch(:key) { nil }
array.fetch(5) { :value }
ENV.fetch(:key) { 'value' }

# good
hash.fetch(:key, 5)
hash.fetch(:key, true)
hash.fetch(:key, nil)
array.fetch(5, :value)
ENV.fetch(:key, 'value')

Further Reading