Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ironnails/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#to_post_parametersObject

returns a string of post parameters for http posts, url-encoded



4
5
6
7
8
9
10
11
12
13
# File 'lib/ironnails/core_ext/hash.rb', line 4

def to_post_parameters
  params = ""

  self.each do |k, v|
    params += "&" unless params.empty?
    params += "#{k}=#{HttpUtility.url_encode(v.to_s.to_clr_string)}"
  end

  params
end

#to_sObject Also known as: to_str, inspect



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ironnails/core_ext/hash.rb', line 15

def to_s
  res = self.collect do |k, v|
    val = case
      when v.is_a?(String)
        "\"#{v}\""
      when v.is_a?(Symbol)
        ":#{v}"
      else
        "#{v}"
    end
    "#{k.is_a?(Symbol) ? ":#{k}" : "#{k}" } => #{val}"
  end
  "{ #{res.join(', ')} }"
end