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.
43 44 45 46 |
# File 'lib/rubocop/cop/performance/sample.rb', line 43 def initialize(shuffle_node) @shuffle_node = shuffle_node @method_node = shuffle_node.parent end |
Instance Method Details
#autocorrect ⇒ Object
48 49 50 |
# File 'lib/rubocop/cop/performance/sample.rb', line 48 def autocorrect ->(corrector) { corrector.replace(source_range, correct) } end |
#message ⇒ Object
52 53 54 |
# File 'lib/rubocop/cop/performance/sample.rb', line 52 def format(MSG, correct: correct, incorrect: source_range.source) end |
#offensive? ⇒ Boolean
56 57 58 |
# File 'lib/rubocop/cop/performance/sample.rb', line 56 def offensive? shuffle_node.to_a[1] == :shuffle && corrigible? end |
#source_range ⇒ Object
60 61 62 63 64 |
# File 'lib/rubocop/cop/performance/sample.rb', line 60 def source_range Parser::Source::Range.new(shuffle_node.source_range.source_buffer, shuffle_node.loc.selector.begin_pos, method_node.source_range.end_pos) end |