Module: EacRubyUtils::EnumerablesMethods

Defined in:
lib/eac_ruby_utils/enumerables_methods.rb

Constant Summary collapse

WRITE_METHOD_PATTERNS =
[/\A[a-z].*[\!\=]\z/i] +
                              %i[\[\]= <<].map { |m| /\A#{::Regexp.quote(m)}\z/ } +
                              %i[add clear delete divide keep reset shift subtract]
.map { |m| /\A#{::Regexp.quote(m)}.*\z/ }
ARRAY_METHODS =
self_methods_names(::Array)
ARRAY_WRITE_METHODS =
ARRAY_METHODS.select { |m| write_method?(m) }
ARRAY_READ_METHODS =
ARRAY_METHODS - ARRAY_WRITE_METHODS
ENUMERABLE_METHODS =
::Enumerable.public_instance_methods.sort
ENUMERABLE_WRITE_METHODS =
ENUMERABLE_METHODS.select { |m| write_method?(m) }
ENUMERABLE_READ_METHODS =
ENUMERABLE_METHODS - ENUMERABLE_WRITE_METHODS
HASH_METHODS =
self_methods_names(::Hash)
HASH_WRITE_METHODS =
HASH_METHODS.select { |m| write_method?(m) }
HASH_READ_METHODS =
HASH_METHODS - HASH_WRITE_METHODS
SET_METHODS =
self_methods_names(::Set)
SET_WRITE_METHODS =
SET_METHODS.select { |m| write_method?(m) } + [:merge]
SET_READ_METHODS =
SET_METHODS - SET_WRITE_METHODS

Class Method Summary collapse

Class Method Details

.self_methods_names(klass) ⇒ Enumerable<Symbol>

Parameters:

  • klass (Klass)

Returns:



15
16
17
# File 'lib/eac_ruby_utils/enumerables_methods.rb', line 15

def self_methods_names(klass)
  (klass.public_instance_methods - klass.superclass.public_instance_methods).sort
end

.write_method?(method_name) ⇒ Boolean

Parameters:

  • method_name (Symbol)

Returns:



21
22
23
# File 'lib/eac_ruby_utils/enumerables_methods.rb', line 21

def write_method?(method_name)
  WRITE_METHOD_PATTERNS.any? { |pattern| pattern.match?(method_name.to_s) }
end