From d0524f1724f7d852f311721a71cc67844cf164d8 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 29 Jul 2012 21:37:30 +0200 Subject: [PATCH] Cleanup Mutant::Method::Classifier * Use constants instead of magic numbers * Use regexp literal. Dunno why it was not used. * Freeze constants --- lib/mutant/matcher/method/classifier.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/mutant/matcher/method/classifier.rb b/lib/mutant/matcher/method/classifier.rb index 7a8f19c6..5faffbd0 100644 --- a/lib/mutant/matcher/method/classifier.rb +++ b/lib/mutant/matcher/method/classifier.rb @@ -8,9 +8,15 @@ module Mutant TABLE = { '.' => Matcher::Method::Singleton, '#' => 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 @@ -59,7 +65,7 @@ module Mutant # @api private # def constant_name - @match[1] + @match[CONSTANT_NAME_POSITION] end # Return method name @@ -69,7 +75,7 @@ module Mutant # @api private # def method_name - @match[3].to_sym + @match[METHOD_NAME_POSITION].to_sym end # Return scope symbol @@ -79,7 +85,7 @@ module Mutant # @api private # def scope_symbol - @match[2] + @match[SCOPE_SYMBOL_POSITION] end # Return matcher class