Skip to content

Commit

Permalink
Use constant to define URI_PARSER
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Sep 1, 2024
1 parent 6c9494b commit c868c2b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mustermann/lib/mustermann/ast/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module AST
# @abstract
# @!visibility private
class Translator

URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new

# Encapsulates a single node translation
# @!visibility private
class NodeTranslator < DelegateClass(Node)
Expand Down Expand Up @@ -118,7 +121,7 @@ def decorator_for(node)

# @return [String] escaped character
# @!visibility private
def escape(char, parser: URI::RFC2396_Parser.new, escape: URI::RFC2396_Parser.new.regexp[:UNSAFE], also_escape: nil)
def escape(char, parser: URI_PARSER, escape: URI_PARSER.regexp[:UNSAFE], also_escape: nil)
escape = Regexp.union(also_escape, escape) if also_escape
char.to_s =~ escape ? parser.escape(char, Regexp.union(*escape)) : char
end
Expand Down

0 comments on commit c868c2b

Please sign in to comment.