Cleanup Mutant::Method::Classifier

* Use constants instead of magic numbers
* Use regexp literal. Dunno why it was not used.
* Freeze constants
This commit is contained in:
Markus Schirp 2012-07-29 21:37:30 +02:00
parent 27f43eef35
commit d0524f1724

View file

@ -8,9 +8,15 @@ module Mutant
TABLE = { TABLE = {
'.' => Matcher::Method::Singleton, '.' => Matcher::Method::Singleton,
'#' => Matcher::Method::Instance '#' => Matcher::Method::Instance
} }.freeze
SCOPE_FORMAT = Regexp.new('\A([^#.]+)(\.|#)(.+)\z') SCOPE_FORMAT = /\A([^#.]+)(\.|#)(.+)\z/.freeze
# Positions of captured regexp groups
# Freezing fixnums to avoid their singleton classes are patched.
CONSTANT_NAME_POSITION = 1.freeze
SCOPE_SYMBOL_POSITION = 2.freeze
METHOD_NAME_POSITION = 3.freeze
private_class_method :new private_class_method :new
@ -59,7 +65,7 @@ module Mutant
# @api private # @api private
# #
def constant_name def constant_name
@match[1] @match[CONSTANT_NAME_POSITION]
end end
# Return method name # Return method name
@ -69,7 +75,7 @@ module Mutant
# @api private # @api private
# #
def method_name def method_name
@match[3].to_sym @match[METHOD_NAME_POSITION].to_sym
end end
# Return scope symbol # Return scope symbol
@ -79,7 +85,7 @@ module Mutant
# @api private # @api private
# #
def scope_symbol def scope_symbol
@match[2] @match[SCOPE_SYMBOL_POSITION]
end end
# Return matcher class # Return matcher class