class Numeric

Constants

EXABYTE
GIGABYTE
KILOBYTE
MEGABYTE
PETABYTE
TERABYTE

Public Instance Methods

byte()
Alias for: bytes
bytes() click to toggle source

Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes

2.bytes # => 2
# File lib/active_support/core_ext/numeric/bytes.rb, line 14
def bytes
  self
end
Also aliased as: byte
day()
Alias for: days
days() click to toggle source

Returns a Duration instance matching the number of days provided.

2.days # => 2 days
# File lib/active_support/core_ext/numeric/time.rb, line 37
def days
  ActiveSupport::Duration.days(self)
end
Also aliased as: day
duplicable?() click to toggle source

Numbers are not duplicable:

3.duplicable? # => false
3.dup         # => TypeError: can't dup Integer
# File lib/active_support/core_ext/object/duplicable.rb, line 101
def duplicable?
  false
end
exabyte()
Alias for: exabytes
exabytes() click to toggle source

Returns the number of bytes equivalent to the exabytes provided.

2.exabytes # => 2_305_843_009_213_693_952
# File lib/active_support/core_ext/numeric/bytes.rb, line 62
def exabytes
  self * EXABYTE
end
Also aliased as: exabyte
fortnight()
Alias for: fortnights
fortnights() click to toggle source

Returns a Duration instance matching the number of fortnights provided.

2.fortnights # => 4 weeks
# File lib/active_support/core_ext/numeric/time.rb, line 53
def fortnights
  ActiveSupport::Duration.weeks(self * 2)
end
Also aliased as: fortnight
gigabyte()
Alias for: gigabytes
gigabytes() click to toggle source

Returns the number of bytes equivalent to the gigabytes provided.

2.gigabytes # => 2_147_483_648
# File lib/active_support/core_ext/numeric/bytes.rb, line 38
def gigabytes
  self * GIGABYTE
end
Also aliased as: gigabyte
hour()
Alias for: hours
hours() click to toggle source

Returns a Duration instance matching the number of hours provided.

2.hours # => 2 hours
# File lib/active_support/core_ext/numeric/time.rb, line 29
def hours
  ActiveSupport::Duration.hours(self)
end
Also aliased as: hour
html_safe?() click to toggle source
# File lib/active_support/core_ext/string/output_safety.rb, line 129
def html_safe?
  true
end
in_milliseconds() click to toggle source

Returns the number of milliseconds equivalent to the seconds provided. Used with the standard time durations.

2.in_milliseconds # => 2000
1.hour.in_milliseconds # => 3600000
# File lib/active_support/core_ext/numeric/time.rb, line 63
def in_milliseconds
  self * 1000
end
kilobyte()
Alias for: kilobytes
kilobytes() click to toggle source

Returns the number of bytes equivalent to the kilobytes provided.

2.kilobytes # => 2048
# File lib/active_support/core_ext/numeric/bytes.rb, line 22
def kilobytes
  self * KILOBYTE
end
Also aliased as: kilobyte
megabyte()
Alias for: megabytes
megabytes() click to toggle source

Returns the number of bytes equivalent to the megabytes provided.

2.megabytes # => 2_097_152
# File lib/active_support/core_ext/numeric/bytes.rb, line 30
def megabytes
  self * MEGABYTE
end
Also aliased as: megabyte
minute()
Alias for: minutes
minutes() click to toggle source

Returns a Duration instance matching the number of minutes provided.

2.minutes # => 2 minutes
# File lib/active_support/core_ext/numeric/time.rb, line 21
def minutes
  ActiveSupport::Duration.minutes(self)
end
Also aliased as: minute
negative?() click to toggle source

Returns true if the number is negative.

-1.negative? # => true
0.negative?  # => false
1.negative?  # => false
# File lib/active_support/core_ext/numeric/inquiry.rb, line 19
def negative?
  self < 0
end
petabyte()
Alias for: petabytes
petabytes() click to toggle source

Returns the number of bytes equivalent to the petabytes provided.

2.petabytes # => 2_251_799_813_685_248
# File lib/active_support/core_ext/numeric/bytes.rb, line 54
def petabytes
  self * PETABYTE
end
Also aliased as: petabyte
positive?() click to toggle source

Returns true if the number is positive.

1.positive?  # => true
0.positive?  # => false
-1.positive? # => false
# File lib/active_support/core_ext/numeric/inquiry.rb, line 10
def positive?
  self > 0
end
second()
Alias for: seconds
seconds() click to toggle source

Returns a Duration instance matching the number of seconds provided.

2.seconds # => 2 seconds
# File lib/active_support/core_ext/numeric/time.rb, line 13
def seconds
  ActiveSupport::Duration.seconds(self)
end
Also aliased as: second
terabyte()
Alias for: terabytes
terabytes() click to toggle source

Returns the number of bytes equivalent to the terabytes provided.

2.terabytes # => 2_199_023_255_552
# File lib/active_support/core_ext/numeric/bytes.rb, line 46
def terabytes
  self * TERABYTE
end
Also aliased as: terabyte
week()
Alias for: weeks
weeks() click to toggle source

Returns a Duration instance matching the number of weeks provided.

2.weeks # => 2 weeks
# File lib/active_support/core_ext/numeric/time.rb, line 45
def weeks
  ActiveSupport::Duration.weeks(self)
end
Also aliased as: week