Module: BetterIpaddr::HostMethods

Included in:
IPAddr::V4::Host, IPAddr::V6::Host
Defined in:
lib/better_ipaddr/host_methods.rb,
lib/better_ipaddr/kernel_method.rb

Overview

Methods included in IPAddr::IPV4::Host and IPAddr::IPV6::Host

Instance Method Summary collapse

Instance Method Details

#cover?(other) ⇒ Boolean

Returns true if the argument is the same as the receiver, false otherwise.

Returns:

  • (Boolean)


11
12
13
# File 'lib/better_ipaddr/host_methods.rb', line 11

def cover?(other)
  self == other
end

#eachEnumerator

Return an enumerator with the behavior described above.

Returns:

  • (Enumerator)


24
25
26
27
28
29
30
# File 'lib/better_ipaddr/host_methods.rb', line 24

def each
  if block_given?
    yield self
  else
    enum_for(:each)
  end
end

#firstIPAddr

Returns the object.

Returns:



35
36
37
# File 'lib/better_ipaddr/host_methods.rb', line 35

def first
  self
end

#host?Boolean

Returns true.

Returns:

  • (Boolean)


41
42
43
# File 'lib/better_ipaddr/host_methods.rb', line 41

def host?
  true
end

#initializeObject



4
5
6
7
# File 'lib/better_ipaddr/host_methods.rb', line 4

def initialize(*)
  super
  @mask_addr = netmask.to_i
end

#inspect(cidr: false, full: false) ⇒ Object

Same as BetterIpaddr::InstanceMethods#inspect but doesn’t by default include the CIDR prefix length.

Returns:

  • String



34
35
36
# File 'lib/better_ipaddr/kernel_method.rb', line 34

def inspect(cidr: false, full: false)
  "#{self.class}['#{better_to_s(cidr: cidr, full: full)}']"
end

#lastIPAddr

Returns the object.

Returns:



48
49
50
# File 'lib/better_ipaddr/host_methods.rb', line 48

def last
  self
end

#netmaskObject

Returns the netmask for a host address.



53
54
55
# File 'lib/better_ipaddr/host_methods.rb', line 53

def netmask
  self.class::HOST_NETMASK
end

#prefix_lengthObject

Returns the number of bits in the address.



58
59
60
# File 'lib/better_ipaddr/host_methods.rb', line 58

def prefix_length
  self.class::BIT_LENGTH
end

#sizeObject

Returns 1.



63
64
65
# File 'lib/better_ipaddr/host_methods.rb', line 63

def size
  1
end