Class: IPAddress::Prefix

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ipaddress/prefix.rb

Overview

NAME

IPAddress::Prefix

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.

Direct Known Subclasses

Prefix128, Prefix32

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num) ⇒ Prefix

Returns a new instance of Prefix.



27
28
29
# File 'lib/ipaddress/prefix.rb', line 27

def initialize(num)
  @prefix = num.to_i
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



25
26
27
# File 'lib/ipaddress/prefix.rb', line 25

def prefix
  @prefix
end

Instance Method Details

#<=>(oth) ⇒ Object



40
41
42
# File 'lib/ipaddress/prefix.rb', line 40

def <=>(oth)
  @prefix <=> oth.to_i
end

#to_iObject



36
37
38
# File 'lib/ipaddress/prefix.rb', line 36

def to_i
  @prefix
end

#to_sObject Also known as: inspect



31
32
33
# File 'lib/ipaddress/prefix.rb', line 31

def to_s
  "#@prefix"
end