- B
- D
- E
- F
- G
- H
- I
- K
- M
- N
- P
- S
- T
- W
KILOBYTE | = | 1024 |
MEGABYTE | = | KILOBYTE * 1024 |
GIGABYTE | = | MEGABYTE * 1024 |
TERABYTE | = | GIGABYTE * 1024 |
PETABYTE | = | TERABYTE * 1024 |
EXABYTE | = | PETABYTE * 1024 |
Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
2.bytes # => 2
Returns a Duration instance matching the number of days provided.
2.days # => 2 days
Numbers are not duplicable:
3.duplicable? # => false
3.dup # => TypeError: can't dup Integer
Returns the number of bytes equivalent to the exabytes provided.
2.exabytes # => 2_305_843_009_213_693_952
Returns a Duration instance matching the number of fortnights provided.
2.fortnights # => 4 weeks
Returns the number of bytes equivalent to the gigabytes provided.
2.gigabytes # => 2_147_483_648
Returns a Duration instance matching the number of hours provided.
2.hours # => 2 hours
Returns the number of milliseconds equivalent to the seconds provided. Used with the standard time durations, like 1.hour.in_milliseconds – so we can feed them to JavaScript functions like getTime().
2.in_milliseconds # => 2_000
Returns the number of bytes equivalent to the kilobytes provided.
2.kilobytes # => 2048
Returns the number of bytes equivalent to the megabytes provided.
2.megabytes # => 2_097_152
Returns a Duration instance matching the number of minutes provided.
2.minutes # => 2 minutes
Returns true if the number is negative.
-1.negative? # => true
0.negative? # => false
1.negative? # => false
Returns the number of bytes equivalent to the petabytes provided.
2.petabytes # => 2_251_799_813_685_248
Returns true if the number is positive.
1.positive? # => true
0.positive? # => false
-1.positive? # => false
Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
These methods use Time#advance for precise date calculations when using from_now, ago, etc. as well as adding or subtracting their results from a Time object. For example:
# equivalent to Time.current.advance(months: 1)
1.month.from_now
# equivalent to Time.current.advance(years: 2)
2.years.from_now
# equivalent to Time.current.advance(months: 4, years: 5)
(4.months + 5.years).from_now