Move more literals to constants
As constans the literals get frozen. This improves sharpness of API use.
This commit is contained in:
parent
243420c7e6
commit
1d981afae8
3 changed files with 6 additions and 5 deletions
|
@ -20,7 +20,9 @@ require 'concord'
|
|||
|
||||
# Library namespace
|
||||
module Mutant
|
||||
end
|
||||
# The empty string used within this namespace
|
||||
EMPTY_STRING = ''.freeze
|
||||
end # Mutant
|
||||
|
||||
require 'mutant/cache'
|
||||
require 'mutant/node_helpers'
|
||||
|
|
|
@ -10,7 +10,8 @@ module Mutant
|
|||
OPERATOR_PATTERN = Regexp.union(*OPERATOR_METHODS.map(&:to_s)).freeze
|
||||
METHOD_NAME_PATTERN = /([_A-Za-z][A-Za-z0-9_]*[!?=]?|#{OPERATOR_PATTERN})/.freeze
|
||||
SCOPE_PATTERN = /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze
|
||||
|
||||
CBASE_PATTERN = /\A::/.freeze
|
||||
SCOPE_OPERATOR = '::'.freeze
|
||||
SINGLETON_PATTERN = %r(\A(#{SCOPE_PATTERN})\z).freeze
|
||||
|
||||
REGISTRY = []
|
||||
|
@ -35,7 +36,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def self.constant_lookup(location)
|
||||
location.gsub(%r(\A::), '').split('::').inject(Object) do |parent, name|
|
||||
location.gsub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR).inject(Object) do |parent, name|
|
||||
parent.const_get(name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,6 @@ module Mutant
|
|||
|
||||
handle(:regexp)
|
||||
|
||||
EMPTY_STRING = ''.freeze
|
||||
|
||||
# No input can ever be matched with this
|
||||
NULL_REGEXP_SOURCE = 'a\A'.freeze
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue