Sha256: f81da094b02b3282a08caa40f715a3c6ad4af7e65e04c3e06a59e5290671093f
Contents?: true
Size: 652 Bytes
Versions: 18
Compression:
Stored size: 652 Bytes
Contents
# Thanks https://mensfeld.pl/2012/01/converting-nested-hash-into-http-url-params-hash-version-in-ruby/ module Jets::Rack module HashConverter def self.encode(value, key = nil, out_hash = {}) case value when Hash then value.each { |k,v| encode(v, append_key(key,k), out_hash) } out_hash when Array then value.each { |v| encode(v, "#{key}[]", out_hash) } out_hash when nil then '' else out_hash[key] = value out_hash end end private def self.append_key(root_key, key) root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]" end end end
Version data entries
18 entries across 18 versions & 1 rubygems