Module: Lazier::Math::ClassMethods

Defined in:
lib/lazier/math.rb

Overview

General methods.

Instance Method Summary (collapse)

Instance Method Details

- (Object) max(*args)

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).



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lazier/math.rb', line 34

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

- (Object) min(*args)

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).



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lazier/math.rb', line 18

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