Methods

Constants

EXABYTE = PETABYTE * 1024
GIGABYTE = MEGABYTE * 1024
KILOBYTE = 1024
MEGABYTE = KILOBYTE * 1024
PETABYTE = TERABYTE * 1024
TERABYTE = GIGABYTE * 1024

Instance Public methods

byte()

Alias for: bytes

bytes()

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

2.bytes # => 2
Also aliased as: byte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 14
  def bytes
    self
  end
🔎 See on GitHub

day()

Alias for: days

days()

Returns a Duration instance matching the number of days provided.

2.days # => 2 days
Also aliased as: day
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 37
  def days
    ActiveSupport::Duration.days(self)
  end
🔎 See on GitHub

duplicable?()

Numbers are not duplicable:

3.duplicable? # => false
3.dup         # => TypeError: can't dup Integer
📝 Source code
# File activesupport/lib/active_support/core_ext/object/duplicable.rb, line 101
    def duplicable?
      false
    end
🔎 See on GitHub

exabyte()

Alias for: exabytes

exabytes()

Returns the number of bytes equivalent to the exabytes provided.

2.exabytes # => 2_305_843_009_213_693_952
Also aliased as: exabyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 62
  def exabytes
    self * EXABYTE
  end
🔎 See on GitHub

fortnight()

Alias for: fortnights

fortnights()

Returns a Duration instance matching the number of fortnights provided.

2.fortnights # => 4 weeks
Also aliased as: fortnight
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 53
  def fortnights
    ActiveSupport::Duration.weeks(self * 2)
  end
🔎 See on GitHub

gigabyte()

Alias for: gigabytes

gigabytes()

Returns the number of bytes equivalent to the gigabytes provided.

2.gigabytes # => 2_147_483_648
Also aliased as: gigabyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 38
  def gigabytes
    self * GIGABYTE
  end
🔎 See on GitHub

hour()

Alias for: hours

hours()

Returns a Duration instance matching the number of hours provided.

2.hours # => 2 hours
Also aliased as: hour
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 29
  def hours
    ActiveSupport::Duration.hours(self)
  end
🔎 See on GitHub

html_safe?()

📝 Source code
# File activesupport/lib/active_support/core_ext/string/output_safety.rb, line 157
  def html_safe?
    true
  end
🔎 See on GitHub

in_milliseconds()

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
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 63
  def in_milliseconds
    self * 1000
  end
🔎 See on GitHub

kilobyte()

Alias for: kilobytes

kilobytes()

Returns the number of bytes equivalent to the kilobytes provided.

2.kilobytes # => 2048
Also aliased as: kilobyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 22
  def kilobytes
    self * KILOBYTE
  end
🔎 See on GitHub

megabyte()

Alias for: megabytes

megabytes()

Returns the number of bytes equivalent to the megabytes provided.

2.megabytes # => 2_097_152
Also aliased as: megabyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 30
  def megabytes
    self * MEGABYTE
  end
🔎 See on GitHub

minute()

Alias for: minutes

minutes()

Returns a Duration instance matching the number of minutes provided.

2.minutes # => 2 minutes
Also aliased as: minute
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 21
  def minutes
    ActiveSupport::Duration.minutes(self)
  end
🔎 See on GitHub

negative?()

Returns true if the number is negative.

-1.negative? # => true
0.negative?  # => false
1.negative?  # => false
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/inquiry.rb, line 19
    def negative?
      self < 0
    end
🔎 See on GitHub

petabyte()

Alias for: petabytes

petabytes()

Returns the number of bytes equivalent to the petabytes provided.

2.petabytes # => 2_251_799_813_685_248
Also aliased as: petabyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 54
  def petabytes
    self * PETABYTE
  end
🔎 See on GitHub

positive?()

Returns true if the number is positive.

1.positive?  # => true
0.positive?  # => false
-1.positive? # => false
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/inquiry.rb, line 10
    def positive?
      self > 0
    end
🔎 See on GitHub

second()

Alias for: seconds

seconds()

Returns a Duration instance matching the number of seconds provided.

2.seconds # => 2 seconds
Also aliased as: second
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 13
  def seconds
    ActiveSupport::Duration.seconds(self)
  end
🔎 See on GitHub

terabyte()

Alias for: terabytes

terabytes()

Returns the number of bytes equivalent to the terabytes provided.

2.terabytes # => 2_199_023_255_552
Also aliased as: terabyte
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/bytes.rb, line 46
  def terabytes
    self * TERABYTE
  end
🔎 See on GitHub

week()

Alias for: weeks

weeks()

Returns a Duration instance matching the number of weeks provided.

2.weeks # => 2 weeks
Also aliased as: week
📝 Source code
# File activesupport/lib/active_support/core_ext/numeric/time.rb, line 45
  def weeks
    ActiveSupport::Duration.weeks(self)
  end
🔎 See on GitHub