class IPAddress::Prefix
NAME¶ ↑
SYNOPSIS¶ ↑
Parent class for Prefix32
and Prefix128
DESCRIPTION¶ ↑
IPAddress::Prefix
is the parent class for IPAddress::Prefix32
and IPAddress::Prefix128
, defining some modules in common for both the subclasses.
IPAddress::Prefix
shouldn’t be accesses directly, unless for particular needs.
Attributes
prefix[R]
Public Class Methods
new(num)
click to toggle source
Creates a new general prefix
# File lib/ipaddress/prefix.rb, line 30 def initialize(num) @prefix = num.to_i end
Public Instance Methods
+(oth)
click to toggle source
Sums two prefixes or a prefix to a number, returns a Integer
# File lib/ipaddress/prefix.rb, line 60 def +(oth) if oth.is_a? Integer self.prefix + oth else self.prefix + oth.prefix end end
-(oth)
click to toggle source
Returns the difference between two prefixes, or a prefix and a number, as a Integer
# File lib/ipaddress/prefix.rb, line 73 def -(oth) if oth.is_a? Integer self.prefix - oth else (self.prefix - oth.prefix).abs end end
<=>(oth)
click to toggle source
Compare the prefix
# File lib/ipaddress/prefix.rb, line 52 def <=>(oth) @prefix <=> oth.to_i end
to_i()
click to toggle source
Returns the prefix
# File lib/ipaddress/prefix.rb, line 45 def to_i @prefix end
to_s()
click to toggle source
Returns a string with the prefix
# File lib/ipaddress/prefix.rb, line 37 def to_s "#@prefix" end
Also aliased as: inspect