lib/ipaddress/ipv4.rb
def subnet(subprefix)
      unless ((@prefix.to_i)..32).include? subprefix
        raise ArgumentError, "New prefix must be between #@prefix and 32"
      end
      Array.new(2**(subprefix-@prefix.to_i)) do |i|
        self.class.parse_u32(network_u32+(i*(2**(32-subprefix))), subprefix)
      end
    end
def subnet(subprefix)
      unless ((@prefix.to_i)..32).include? subprefix
        raise ArgumentError, "New prefix must be between #@prefix and 32"
      end
      Array.new(2**(subprefix-@prefix.to_i)) do |i|
        self.class.parse_u32(network_u32+(i*(2**(32-subprefix))), subprefix)
      end
    end
This method implements the subnetting function
 similar to the one described in RFC3531.

 By specifying a new prefix, the method calculates
 the network number for the given IPv4 object
 and calculates the subnets associated to the new
 prefix.

 For example, given the following network:

   ip = IPAddress "172.16.10.0/24"

 we can calculate the subnets with a /26 prefix

   ip.subnet(26).map{&:to_string)
     #=> ["172.16.10.0/26", "172.16.10.64/26",
          "172.16.10.128/26", "172.16.10.192/26"]

 The resulting number of subnets will of course always be
 a power of two.