Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/ipaddress/extensions/extensions.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#closest_power_of_2(limit = 32) ⇒ Object



16
17
18
19
20
# File 'lib/ipaddress/extensions/extensions.rb', line 16

def closest_power_of_2(limit=32)
  self.upto(limit) do |i|
    return i if i.power_of_2?
  end
end

#power_of_2?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ipaddress/extensions/extensions.rb', line 12

def power_of_2?
  Math::log2(self).to_i == Math::log2(self)
end