Skip to content

Commit 4aa4476

Browse files
committed
Optimize Util.valid_variable_name? method
1 parent d7315e3 commit 4aa4476

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

lib/stripe/util.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
module Stripe
66
module Util
7-
LEGAL_FIRST_CHARACTER = /[a-zA-Z_]/.freeze
8-
LEGAL_VARIABLE_CHARACTER = /[a-zA-Z0-9_]/.freeze
9-
107
def self.objects_to_ids(obj)
118
case obj
129
when APIResource
@@ -323,9 +320,7 @@ def self.normalize_opts(opts)
323320
# Return false for strings that are invalid variable names
324321
# Does NOT expect there to be a preceding '@' for instance variables
325322
def self.valid_variable_name?(key)
326-
return false if key.empty? || key[0] !~ LEGAL_FIRST_CHARACTER
327-
328-
key[1..].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
323+
key.match?(/\A[a-zA-Z_]\w*\z/)
329324
end
330325

331326
def self.check_string_argument!(key)

0 commit comments

Comments
 (0)