def normalize_path(path)
    normalized_path = path.dup
    begin
      mod = nil
      mod ||= normalized_path.gsub!(RULE_2A, '/')

      pair = normalized_path.match(RULE_2B_2C)
      parent, current = pair[1], pair[2] if pair
      if pair && ((parent != '.' && parent != '..') ||
          (current != '.' && current != '..'))
        mod ||= normalized_path.gsub!(
          Regexp.new(
            "/#{Regexp.escape(parent.to_s)}/\\.\\./|" +
            "(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
          ), '/'
        )
      end

      mod ||= normalized_path.gsub!(RULE_2D, '')
      # Non-standard, removes prefixed dotted segments from path.
      mod ||= normalized_path.gsub!(RULE_PREFIXED_PARENT, '/')
    end until mod.nil?

    return normalized_path
  end
def normalize_path(path)
    normalized_path = path.dup
    begin
      mod = nil
      mod ||= normalized_path.gsub!(RULE_2A, '/')

      pair = normalized_path.match(RULE_2B_2C)
      parent, current = pair[1], pair[2] if pair
      if pair && ((parent != '.' && parent != '..') ||
          (current != '.' && current != '..'))
        mod ||= normalized_path.gsub!(
          Regexp.new(
            "/#{Regexp.escape(parent.to_s)}/\\.\\./|" +
            "(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
          ), '/'
        )
      end

      mod ||= normalized_path.gsub!(RULE_2D, '')
      # Non-standard, removes prefixed dotted segments from path.
      mod ||= normalized_path.gsub!(RULE_PREFIXED_PARENT, '/')
    end until mod.nil?

    return normalized_path
  end
Resolves paths to their simplest form.
 Shamelessly lifted from https://github.com/sporkmonger/addressable