Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/mugen/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#normalize_param(key, value) ⇒ Object

This hack to enables CGI::escape instead of URI.encode in to_params



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mugen/core_extensions.rb', line 8

def normalize_param(key, value)
  param = ''
  stack = []

  if value.is_a?(Array)
    param << value.map { |element| normalize_param("#{key}[]", element) }.join
  elsif value.is_a?(Hash)
    stack << [key,value]
  else
    param << "#{key}=#{CGI::escape(value.to_s)}&"            
  end

  stack.each do |parent, hash|
    hash.each do |key, value|
      if value.is_a?(Hash)
        stack << ["#{parent}[#{key}]", value]
      else
        param << normalize_param("#{parent}[#{key}]", value)
      end
    end
  end

  param
end

#sorted_hashObject



3
4
5
# File 'lib/mugen/core_extensions.rb', line 3

def sorted_hash
  self.keys.sort
end