Module: Mutant::Result::ClassMethods Private

Defined in:
lib/mutant/result.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class level mixin

Instance Method Summary collapse

Instance Method Details

#sum(name, collection) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate a sum method from name and collection

Parameters:

  • name (Symbol)

    the attribute name on collection item and method name to use

  • collection (Symbol)

    the attribute name used to receive collection

Returns:

  • (undefined)


36
37
38
39
40
41
# File 'lib/mutant/result.rb', line 36

def sum(name, collection)
  define_method(name) do
    public_send(collection).map(&name).reduce(0, :+)
  end
  memoize(name)
end