Sha256: 873fa5bd2344d75ac5c9021b4dbceb766e01238cf44ba231d120e3901ce894be

Contents?: true

Size: 702 Bytes

Versions: 6

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

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

6 entries across 6 versions & 1 rubygems

Version Path
web_translate_it-3.1.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-3.1.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-3.0.2 lib/web_translate_it/util/hash_util.rb
web_translate_it-3.0.1 lib/web_translate_it/util/hash_util.rb
web_translate_it-3.0.0 lib/web_translate_it/util/hash_util.rb
web_translate_it-3.0.0.beta1 lib/web_translate_it/util/hash_util.rb