Skip to content

Files

Latest commit

 

History

History
29 lines (18 loc) · 707 Bytes

Style-HashConversion.md

File metadata and controls

29 lines (18 loc) · 707 Bytes

Pattern: Malformed hash conversion

Issue: -

Description

Checks the usage of pre-2.1 Hash[args] method of converting enumerables and sequences of values to hashes.

Correction code from splat argument (Hash[*ary]) is not simply determined. For example, Hash[*ary] can be replaced with ary.each_slice(2).to_h but it will be complicated. So, AllowSplatArgument option is true by default to allow splat argument for simple code.

Examples

# bad
Hash[ary]

# good
ary.to_h

# bad
Hash[key1, value1, key2, value2]

# good
{key1 => value1, key2 => value2}

Further Reading