Sha256: aac8c72e86ac7781e53dd9cb3722f3e0c127814d50c9dffd6f3706edb41df484

Contents?: true

Size: 667 Bytes

Versions: 5

Compression:

Stored size: 667 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

5 entries across 5 versions & 1 rubygems

Version Path
web_translate_it-2.6.3 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.6.3.pre1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.6.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.6.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-2.6.0 lib/web_translate_it/util/hash_util.rb