Method: IPAddress::IPv4#last

Defined in:
lib/ipaddress_2/ipv4.rb

#lastObject

Like its sibling method IPv4#first, this method returns a new IPv4 object with the last host IP address in the range.

Example: given the 192.168.100.0/24 network, the last host IP address is 192.168.100.254

ip = IPAddress("192.168.100.0/24")

ip.last.to_s
  #=> "192.168.100.254"

The object IP doesn’t need to be a network: the method automatically gets the network number from it

ip = IPAddress("192.168.100.50/24")

ip.last.to_s
  #=> "192.168.100.254"


445
446
447
448
449
450
451
452
453
454
# File 'lib/ipaddress_2/ipv4.rb', line 445

def last
  case
  when prefix <= 30
    self.class.parse_u32(broadcast_u32-1, @prefix)
  when prefix == 31
    self.class.parse_u32(broadcast_u32, @prefix)
  when prefix == 32
    return self
  end
end