Module: IpAddresslike
Constant Summary collapse
- ONES =
0xFFFFFFFF
Instance Method Summary collapse
-
#bitness_max(bitness) ⇒ Object
Masks off all but the
bitness
most-significant-bits, filling with ones. -
#bitness_min(bitness) ⇒ Object
Masks off all but the
bitness
most-significant-bits. - #to_hex ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#bitness_max(bitness) ⇒ Object
Masks off all but the bitness
most-significant-bits, filling with ones
20 21 22 23 |
# File 'lib/gorillib/type/ip_address.rb', line 20 def bitness_max(bitness) raise ArgumentError, "IP addresses have only 32 bits (got #{bitness.inspect})" unless (0..32).include?(bitness) packed | (ONES >> bitness) end |
#bitness_min(bitness) ⇒ Object
Masks off all but the bitness
most-significant-bits
9 10 11 12 13 |
# File 'lib/gorillib/type/ip_address.rb', line 9 def bitness_min(bitness) raise ArgumentError, "IP addresses have only 32 bits (got #{bitness.inspect})" unless (0..32).include?(bitness) lsbs = 32 - bitness (packed >> lsbs) << lsbs end |
#to_hex ⇒ Object
25 26 27 |
# File 'lib/gorillib/type/ip_address.rb', line 25 def to_hex "%08x" % packed end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/gorillib/type/ip_address.rb', line 29 def to_s dotted end |