Sha256: 3dc88e89501fff416b4170faa06d8a55883a715c3450adfc69a82e8a0860bf51

Contents?: true

Size: 1.44 KB

Versions: 192

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

class Numeric
  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
  def bytes
    self
  end
  alias :byte :bytes

  # Returns the number of bytes equivalent to the kilobytes provided.
  #
  #   2.kilobytes # => 2048
  def kilobytes
    self * KILOBYTE
  end
  alias :kilobyte :kilobytes

  # Returns the number of bytes equivalent to the megabytes provided.
  #
  #   2.megabytes # => 2_097_152
  def megabytes
    self * MEGABYTE
  end
  alias :megabyte :megabytes

  # Returns the number of bytes equivalent to the gigabytes provided.
  #
  #   2.gigabytes # => 2_147_483_648
  def gigabytes
    self * GIGABYTE
  end
  alias :gigabyte :gigabytes

  # Returns the number of bytes equivalent to the terabytes provided.
  #
  #   2.terabytes # => 2_199_023_255_552
  def terabytes
    self * TERABYTE
  end
  alias :terabyte :terabytes

  # Returns the number of bytes equivalent to the petabytes provided.
  #
  #   2.petabytes # => 2_251_799_813_685_248
  def petabytes
    self * PETABYTE
  end
  alias :petabyte :petabytes

  # Returns the number of bytes equivalent to the exabytes provided.
  #
  #   2.exabytes # => 2_305_843_009_213_693_952
  def exabytes
    self * EXABYTE
  end
  alias :exabyte :exabytes
end

Version data entries

192 entries across 178 versions & 24 rubygems

Version Path
activesupport-7.0.8.6 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.10 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.9 lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.8.5 lib/active_support/core_ext/numeric/bytes.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/core_ext/numeric/bytes.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/core_ext/numeric/bytes.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/core_ext/numeric/bytes.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.8.4 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.8 lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.8.1 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.7 lib/active_support/core_ext/numeric/bytes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/core_ext/numeric/bytes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.2.3/lib/active_support/core_ext/numeric/bytes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.8 lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.7.2 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.6 lib/active_support/core_ext/numeric/bytes.rb
activesupport-7.0.7.1 lib/active_support/core_ext/numeric/bytes.rb
activesupport-6.1.7.5 lib/active_support/core_ext/numeric/bytes.rb