Class: IPAddress::Prefix128
Overview
class Prefix32 < Prefix
Instance Attribute Summary
Attributes inherited from Prefix
Instance Method Summary collapse
-
#bits ⇒ Object
Transforms the prefix into a string of bits representing the netmask.
-
#host_prefix ⇒ Object
Returns the length of the host portion of a netmask.
-
#initialize(num = 128) ⇒ Prefix128
constructor
Creates a new prefix object for 128 bits IPv6 addresses.
-
#to_u128 ⇒ Object
Unsigned 128 bits decimal number representing the prefix.
Methods inherited from Prefix
#+, #-, #<=>, #coerce, #to_i, #to_s
Constructor Details
#initialize(num = 128) ⇒ Prefix128
236 237 238 239 240 241 |
# File 'lib/ipaddress_2/prefix.rb', line 236 def initialize(num=128) unless (0..128).include? num.to_i raise ArgumentError, "Prefix must be in range 0..128, got: #{num}" end super(num.to_i) end |
Instance Method Details
#bits ⇒ Object
253 254 255 |
# File 'lib/ipaddress_2/prefix.rb', line 253 def bits "1" * @prefix + "0" * (128 - @prefix) end |
#host_prefix ⇒ Object
279 280 281 |
# File 'lib/ipaddress_2/prefix.rb', line 279 def host_prefix 128 - @prefix end |