Class: RuboCop::Cop::Performance::Sample::ShuffleAnalyzer
- Inherits:
-
Object
- Object
- RuboCop::Cop::Performance::Sample::ShuffleAnalyzer
- Defined in:
- lib/rubocop/cop/performance/sample.rb
Overview
An internal class for representing a shuffle + method node analyzer.
Instance Method Summary collapse
- #autocorrect ⇒ Object
-
#initialize(shuffle_node) ⇒ ShuffleAnalyzer
constructor
A new instance of ShuffleAnalyzer.
- #message ⇒ Object
- #offensive? ⇒ Boolean
- #source_range ⇒ Object
Constructor Details
#initialize(shuffle_node) ⇒ ShuffleAnalyzer
Returns a new instance of ShuffleAnalyzer.
42 43 44 45 |
# File 'lib/rubocop/cop/performance/sample.rb', line 42 def initialize(shuffle_node) @shuffle_node = shuffle_node @method_node = shuffle_node.parent end |
Instance Method Details
#autocorrect ⇒ Object
47 48 49 |
# File 'lib/rubocop/cop/performance/sample.rb', line 47 def autocorrect ->(corrector) { corrector.replace(source_range, correct) } end |
#message ⇒ Object
51 52 53 |
# File 'lib/rubocop/cop/performance/sample.rb', line 51 def format(MSG, correct: correct, incorrect: source_range.source) end |
#offensive? ⇒ Boolean
55 56 57 |
# File 'lib/rubocop/cop/performance/sample.rb', line 55 def offensive? shuffle_node.to_a[1] == :shuffle && corrigible? end |
#source_range ⇒ Object
59 60 61 62 63 |
# File 'lib/rubocop/cop/performance/sample.rb', line 59 def source_range Parser::Source::Range.new(shuffle_node.loc.expression.source_buffer, shuffle_node.loc.selector.begin_pos, method_node.loc.expression.end_pos) end |