class String def increment_version array = self.split('.') digits = 0 index_of_last_digit = 0 array.each_with_index {|x, i| if x.is_number? then digits += 1 index_of_last_digit = i end break if (digits==3 || i==array.count-1) && x.is_number? } array[index_of_last_digit] = (array[index_of_last_digit].to_i + 1).to_s $stdout.puts 'Incrementing version...' array.join('.') end def increment_version! replace increment_version end def is_number? true if Float(self) rescue false end end