Skip to content

Commit f625a9f

Browse files
committed
Make MatchData backref_from_arg logic easier to read
1 parent dc54aee commit f625a9f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/ruby/truffleruby/core/match_data.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ def to_s
169169
def backref_from_arg(index)
170170
if Primitive.is_a?(index, String) || Primitive.is_a?(index, Symbol)
171171
names_to_backref = Hash[Primitive.regexp_names(self.regexp)]
172-
unless names_to_backref.key?(index.to_sym)
173-
raise IndexError, "undefined group name reference: #{index}"
174-
end
175-
names_to_backref[index.to_sym].last
176-
else
177-
Primitive.rb_to_int(index)
172+
key = index.to_sym
173+
174+
raise IndexError, "undefined group name reference: #{index}" unless names_to_backref.key?(key)
175+
176+
return names_to_backref[key].last
178177
end
178+
179+
Primitive.rb_to_int(index)
179180
end
180181
end
181182

0 commit comments

Comments
 (0)