Simplify method expansions
This commit is contained in:
parent
9f7d33be6f
commit
4d89c02041
2 changed files with 7 additions and 7 deletions
|
@ -10,10 +10,10 @@ module Mutant
|
||||||
undef unless until when while yield
|
undef unless until when while yield
|
||||||
).map(&:to_sym).to_set.freeze
|
).map(&:to_sym).to_set.freeze
|
||||||
|
|
||||||
METHOD_NAME_EXPANSIONS = {
|
METHOD_POSTFIX_EXPANSIONS = {
|
||||||
/\?\z/ => '_predicate',
|
'?' => '_predicate',
|
||||||
/=\z/ => '_writer',
|
'=' => '_writer',
|
||||||
/!\z/ => '_bang'
|
'!' => '_bang'
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
BINARY_METHOD_OPERATOR_EXPANSIONS = {
|
BINARY_METHOD_OPERATOR_EXPANSIONS = {
|
||||||
|
|
|
@ -31,6 +31,8 @@ module Mutant
|
||||||
end
|
end
|
||||||
private_class_method :map
|
private_class_method :map
|
||||||
|
|
||||||
|
REGEXP = /#{Regexp.union(*METHOD_POSTFIX_EXPANSIONS.keys)}\z/.freeze
|
||||||
|
|
||||||
# Return expanded name
|
# Return expanded name
|
||||||
#
|
#
|
||||||
# @param [Symbol] name
|
# @param [Symbol] name
|
||||||
|
@ -40,9 +42,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def self.expand(name)
|
def self.expand(name)
|
||||||
METHOD_NAME_EXPANSIONS.inject(name.to_s) do |name, find_replace|
|
name.to_s.gsub(REGEXP, METHOD_POSTFIX_EXPANSIONS).to_sym
|
||||||
name.gsub(*find_replace)
|
|
||||||
end.to_sym
|
|
||||||
end
|
end
|
||||||
private_class_method :expand
|
private_class_method :expand
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue