Sha256: 01d9e78305efa6466ac04d555693b63fdc0a76d2bbb5fc7519659e0d89fc0851

Contents?: true

Size: 635 Bytes

Versions: 44

Compression:

Stored size: 635 Bytes

Contents

class HashUtil
  def self.to_params(hash)
    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, hash|
      hash.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

44 entries across 44 versions & 1 rubygems

Version Path
web_translate_it-2.5.4 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.5.3 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.5.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.5.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.5.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.12 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.11 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.10 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.9 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.8 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.7 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.6 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.5 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.4 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.3 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.4.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.3.4 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.3.3 lib/web_translate_it/util/hash_util.rb