Simplify method expansions

This commit is contained in:
Markus Schirp 2013-02-22 20:46:22 +01:00
parent 9f7d33be6f
commit 4d89c02041
2 changed files with 7 additions and 7 deletions

View file

@ -10,10 +10,10 @@ module Mutant
undef unless until when while yield
).map(&:to_sym).to_set.freeze
METHOD_NAME_EXPANSIONS = {
/\?\z/ => '_predicate',
/=\z/ => '_writer',
/!\z/ => '_bang'
METHOD_POSTFIX_EXPANSIONS = {
'?' => '_predicate',
'=' => '_writer',
'!' => '_bang'
}.freeze
BINARY_METHOD_OPERATOR_EXPANSIONS = {

View file

@ -31,6 +31,8 @@ module Mutant
end
private_class_method :map
REGEXP = /#{Regexp.union(*METHOD_POSTFIX_EXPANSIONS.keys)}\z/.freeze
# Return expanded name
#
# @param [Symbol] name
@ -40,9 +42,7 @@ module Mutant
# @api private
#
def self.expand(name)
METHOD_NAME_EXPANSIONS.inject(name.to_s) do |name, find_replace|
name.gsub(*find_replace)
end.to_sym
name.to_s.gsub(REGEXP, METHOD_POSTFIX_EXPANSIONS).to_sym
end
private_class_method :expand