Skip to content

Commit 1e35390

Browse files
fmangfwininger
authored andcommitted
Fix Rubocop
String.new and +'' have the subtle difference that the encoding of the former in BINARY and the latter use the source encoding. +'' is therefore closer to historical behavior.
1 parent 8bc08b0 commit 1e35390

2 files changed

Lines changed: 32 additions & 22 deletions

File tree

.rubocop.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ Layout/LineLength:
1717

1818
Naming/MethodName:
1919
Enabled: false
20+
21+
Metrics:
22+
Enabled: false
23+
24+
RSpec/MultipleExpectations:
25+
Enabled: false
26+
27+
RSpec/ExampleLength:
28+
Enabled: false

lib/software_version/version.rb

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,34 @@ def tokens
9696
# Associate characters to their token types. Multiple characters of the
9797
# same type are grouped together to form a single unit.
9898
CHARACTERS_TOKEN = {
99-
'.' => Token::DOT,
100-
',' => Token::DOT,
101-
'~' => Token::TILDE,
102-
'+' => Token::PLUS,
103-
'-' => Token::DASH,
104-
':' => Token::COLON,
105-
'^' => Token::CARET,
106-
'_' => Token::UNDERSCORE,
107-
' ' => Token::UNDERSCORE,
108-
'0' => Token::NUMBER,
109-
'1' => Token::NUMBER,
110-
'2' => Token::NUMBER,
111-
'3' => Token::NUMBER,
112-
'4' => Token::NUMBER,
113-
'5' => Token::NUMBER,
114-
'6' => Token::NUMBER,
115-
'7' => Token::NUMBER,
116-
'8' => Token::NUMBER,
117-
'9' => Token::NUMBER,
118-
}.tap { |h| h.default = Token::WORD }.freeze
99+
'.' => Token::DOT,
100+
',' => Token::DOT,
101+
'~' => Token::TILDE,
102+
'+' => Token::PLUS,
103+
'-' => Token::DASH,
104+
':' => Token::COLON,
105+
'^' => Token::CARET,
106+
'_' => Token::UNDERSCORE,
107+
' ' => Token::UNDERSCORE,
108+
'0' => Token::NUMBER,
109+
'1' => Token::NUMBER,
110+
'2' => Token::NUMBER,
111+
'3' => Token::NUMBER,
112+
'4' => Token::NUMBER,
113+
'5' => Token::NUMBER,
114+
'6' => Token::NUMBER,
115+
'7' => Token::NUMBER,
116+
'8' => Token::NUMBER,
117+
'9' => Token::NUMBER,
118+
}.tap { |h| h.default = Token::WORD }.freeze
119+
private_constant :CHARACTERS_TOKEN
119120

120121
# Cut the version string into literal tokens, without further
121122
# interpretation. 1:2.3beta becomes NUMBER COLON NUMBER NUMBER WORD EOV. Returns an Array of Token.
122123
def lex(version_string)
123124
tokens = []
124125
chunk_type = nil
125-
chunk_value = String.new
126+
chunk_value = +''
126127
commit = ->() {
127128
case chunk_type
128129
when nil then return
@@ -131,7 +132,7 @@ def lex(version_string)
131132
else tokens << [chunk_type, chunk_value]
132133
end
133134
chunk_type = nil
134-
chunk_value = String.new
135+
chunk_value = +''
135136
}
136137
version_string.each_char do |c|
137138
char_type = CHARACTERS_TOKEN[c]

0 commit comments

Comments
 (0)