class RuboCop::Cop::Style::StringChars
Checks for uses of ‘String#split` with empty string or regexp literal argument.
@safety
This cop is unsafe because it cannot be guaranteed that the receiver is actually a string. If another class has a `split` method with different behavior, it would be registered as a false positive.
@example
# bad string.split(//) string.split('') # good string.chars
Constants
- BAD_ARGUMENTS
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
Source
# File lib/rubocop/cop/style/string_chars.rb, line 29 def on_send(node) return unless node.arguments.one? && BAD_ARGUMENTS.include?(node.first_argument.source) range = range_between(node.loc.selector.begin_pos, node.source_range.end_pos) add_offense(range, message: format(MSG, current: range.source)) do |corrector| corrector.replace(range, 'chars') end end
Also aliased as: on_csend