Module: Cowtech::Extensions::Math::ClassMethods

Defined in:
lib/cowtech-extensions/math.rb

Overview

General methods.

Instance Method Summary collapse

Instance Method Details

#max(*args) ⇒ Object

Returns the maximum value in the arguments

Parameters:

  • args (Array)

    A collection of object to compare (with the > operator).

Returns:

  • (Object)

    The maximum value or nil (if the collection is empty).



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cowtech-extensions/math.rb', line 35

def max(*args)
  rv = nil

  args = args.ensure_array.flatten
  if args.length > 0 then
    rv = args[0]
    args.each do |a| rv = a if a > rv end
  end

  rv
end

#min(*args) ⇒ Object

Returns the minimum value in the arguments

Parameters:

  • args (Array)

    A collection of object to compare (with the < operator).

Returns:

  • (Object)

    The minimum value or nil (if the collection is empty).



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cowtech-extensions/math.rb', line 19

def min(*args)
  rv = nil

  args = args.ensure_array.flatten
  if args.length > 0 then
    rv = args[0]
    args.each do |a| rv = a if a < rv end
  end

  rv
end