Sha256: 89f00653f4e61ffa4b5b8483320800a44468632f2f024cca6b511cdea454bb4b

Contents?: true

Size: 584 Bytes

Versions: 8

Compression:

Stored size: 584 Bytes

Contents

# frozen_string_literal: true
# typed: true

# rubocop:disable Style/Documentation

class Integer
  # rubocop:enable Style/Documentation
  extend T::Sig
  # Aligns the integer to the nearest multiple of the alignment.
  # @param alignment [Integer] the alignment
  # @return [Integer] the aligned integer
  sig { params(alignment: T.nilable(Integer)).returns(Integer) }
  def align(alignment = nil)
    alignment ||= Integer.size

    return self if alignment < 2

    alignment -= 1

    if (self & alignment).zero?
      self
    else
      (self | alignment) + 1
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mootool-0.2.7 lib/mootool/core_extensions.rb
mootool-0.2.6 lib/mootool/core_extensions.rb
mootool-0.2.5 lib/mootool/core_extensions.rb
mootool-0.2.4 lib/mootool/core_extensions.rb
mootool-0.2.3 lib/mootool/core_extensions.rb
mootool-0.2.2 lib/mootool/core_extensions.rb
mootool-0.2.1 lib/mootool/core_extensions.rb
mootool-0.2 lib/mootool/core_extensions.rb