Class: Integer

Inherits:
Object show all
Defined in:
lib/patch/foobar.rb

Overview

Extends the Integer class with methods for time durations and comparisons.

Instance Method Summary collapse

Instance Method Details

#dayInteger

Converts the integer (assumed to be days) into seconds.

Returns:



177
# File 'lib/patch/foobar.rb', line 177

def day; self * 24.hour end

#hourInteger

Converts the integer (assumed to be hours) into seconds.

Returns:



173
# File 'lib/patch/foobar.rb', line 173

def hour; self * 60.minute end

#max(*xs) ⇒ Numeric

Returns the maximum of self and the given numeric values.

Examples:

5.max(3, 4, 11) # => 11
-1.max(-5, 0)   # => 0
10.max(2)       # => 10

Parameters:

  • `xs` (Array<Numeric>)

    Zero or more numeric values to compare against.

Returns:

  • (Numeric)

    The largest value among self and xs.



212
213
214
215
# File 'lib/patch/foobar.rb', line 212

def max(*xs)
  xs.push(self)
  xs.max
end

#min(*xs) ⇒ Numeric

Returns the minimum of self and the given numeric values.

Examples:

5.min(3, 4, 2)  # => 2
-1.min(0, 1)    # => -1
10.min(20)      # => 10

Parameters:

  • `xs` (Array<Numeric>)

    Zero or more numeric values to compare against.

Returns:

  • (Numeric)

    The smallest value among self and xs.



199
200
201
202
# File 'lib/patch/foobar.rb', line 199

def min(*xs)
  xs.push(self)
  xs.min
end

#minuteInteger

Converts the integer (assumed to be minutes) into seconds.

Returns:



169
# File 'lib/patch/foobar.rb', line 169

def minute; self * 60.second end

#monthInteger

Converts the integer (assumed to be months, approximated as 4 weeks) into seconds.

Returns:



185
# File 'lib/patch/foobar.rb', line 185

def month; self * 4.week end

#secondInteger

Represents the integer as a duration in seconds.

Returns:



165
# File 'lib/patch/foobar.rb', line 165

def second; self end

#weekInteger

Converts the integer (assumed to be weeks) into seconds.

Returns:



181
# File 'lib/patch/foobar.rb', line 181

def week; self * 7.day end

#yearInteger

Converts the integer (assumed to be years) into seconds.

Returns:



189
# File 'lib/patch/foobar.rb', line 189

def year; self * 12.month end