Sha256: 16778d68f90ca57f1eb635d903392ebe96d1c91cc5b63f081c85df6a52d1c34e

Contents?: true

Size: 671 Bytes

Versions: 13

Compression:

Stored size: 671 Bytes

Contents

class HashUtil

  def self.to_params(hash) # rubocop:todo Metrics/MethodLength
    params = ''
    stack = []

    hash.each do |k, v|
      if v.is_a?(Hash)
        stack << [k, v]
      else
        params << "#{k}=#{v}&"
      end
    end

    stack.each do |parent, h|
      h.each do |k, v|
        if v.is_a?(Hash)
          stack << ["#{parent}[#{k}]", v]
        else
          params << "#{parent}[#{k}]=#{v}&"
        end
      end
    end

    params.chop! # trailing &
    params
  end

end

class Hash

  # Destructively convert all keys to strings.
  def stringify_keys!
    keys.each do |key|
      self[key.to_s] = delete(key)
    end
    self
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
web_translate_it-2.8.3 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.8.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.8.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.8.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.8.0.pre.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.6 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.5 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.4 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.3 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.7.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.6.4 lib/web_translate_it/util/hash_util.rb