Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 548 Bytes

Style-ArrayCoercion.md

File metadata and controls

25 lines (16 loc) · 548 Bytes

Pattern: Missing use of Array()

Issue: -

Description

Enforces the use of Array() instead of explicit Array check or [*var].

Examples

# bad
paths = [paths] unless paths.is_a?(Array)
paths.each { |path| do_something(path) }

# bad (always creates a new Array instance)
[*paths].each { |path| do_something(path) }

# good (and a bit more readable)
Array(paths).each { |path| do_something(path) }

Further Reading