Method: IPAddress::IPv4#first

Defined in:
lib/ipaddress/ipv4.rb

#firstObject

Returns a new IPv4 object with the first host IP address in the range.

Example: given the 192.168.100.0/24 network, the first host IP address is 192.168.100.1.

ip = IPAddress("192.168.100.0/24")

ip.first.to_s
  #=> "192.168.100.1"

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.first.to_s
  #=> "192.168.100.1"


387
388
389
390
391
392
393
394
395
396
# File 'lib/ipaddress/ipv4.rb', line 387

def first
  case
  when prefix <= 30
    self.class.parse_u32(network_u32+1, @prefix)
  when prefix == 31
    self.class.parse_u32(network_u32, @prefix)
  when prefix == 32
    return self
  end
end