module Clusterfuck class SubnetFactory attr_reader :subnet START_SUBNET = "10.0.39.0/24" @previous = IPAddr.new(START_SUBNET) def initialize(subnet) @subnet = subnet end def next @subnet = @subnet.succ end def self.next(cidr = 24) # succ twice to start at x.x.x.2 @previous = @previous.mask(cidr).to_range.last.succ.succ SubnetFactory.new(@previous) end def self.reset @previous = IPAddr.new(START_SUBNET) end end end