Skip to content

Files

Latest commit

 

History

History
48 lines (36 loc) · 657 Bytes

Performance-RedundantStringChars.md

File metadata and controls

48 lines (36 loc) · 657 Bytes

Pattern: Redundant String#chars

Issue: -

Description

Checks for redundant String#chars.

Examples

# bad
str.chars[0..2]
str.chars.slice(0..2)

# good
str[0..2].chars

# bad
str.chars.first
str.chars.first(2)
str.chars.last
str.chars.last(2)

# good
str[0]
str[0...2].chars
str[-1]
str[-2..-1].chars

# bad
str.chars.take(2)
str.chars.drop(2)
str.chars.length
str.chars.size
str.chars.empty?

# good
str[0...2].chars
str[2..-1].chars
str.length
str.size
str.empty?

Further Reading