Skip to content

Commit b1c67e9

Browse files
committed
Constantize fixed arrays of Style/SymbolArray
1 parent aab9391 commit b1c67e9

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/rubocop/cop/style/symbol_array.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ class SymbolArray < Base
5050
PERCENT_MSG = 'Use `%i` or `%I` for an array of symbols.'
5151
ARRAY_MSG = 'Use %<prefer>s for an array of symbols.'
5252
DELIMITERS = ['[', ']', '(', ')'].freeze
53+
SPECIAL_GVARS = %w[
54+
$! $" $$ $& $' $* $+ $, $/ $; $: $. $< $= $> $? $@ $\\ $_ $` $~ $0
55+
$-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w
56+
].freeze
57+
REDEFINABLE_OPERATORS = %w(
58+
| ^ & <=> == === =~ > >= < <= << >>
59+
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
60+
).freeze
5361

5462
class << self
5563
attr_accessor :largest_brackets
@@ -109,24 +117,15 @@ def to_symbol_literal(string)
109117
end
110118

111119
def symbol_without_quote?(string)
112-
special_gvars = %w[
113-
$! $" $$ $& $' $* $+ $, $/ $; $: $. $< $= $> $? $@ $\\ $_ $` $~ $0
114-
$-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w
115-
]
116-
redefinable_operators = %w(
117-
| ^ & <=> == === =~ > >= < <= << >>
118-
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
119-
)
120-
121120
# method name
122121
/\A[a-zA-Z_]\w*[!?]?\z/.match?(string) ||
123122
# instance / class variable
124123
/\A@@?[a-zA-Z_]\w*\z/.match?(string) ||
125124
# global variable
126125
/\A\$[1-9]\d*\z/.match?(string) ||
127126
/\A\$[a-zA-Z_]\w*\z/.match?(string) ||
128-
special_gvars.include?(string) ||
129-
redefinable_operators.include?(string)
127+
SPECIAL_GVARS.include?(string) ||
128+
REDEFINABLE_OPERATORS.include?(string)
130129
end
131130
end
132131
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy