Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#keyObject



10
11
12
# File 'lib/gattica/core_extensions.rb', line 10

def key
  self.keys.first if self.length == 1
end

#stringify_keysObject



18
19
20
21
22
23
# File 'lib/gattica/core_extensions.rb', line 18

def stringify_keys
  inject({}) do |options, (key, value)|
    options[key.to_s] = value
    options
  end
end

#to_queryObject



3
4
5
6
7
8
# File 'lib/gattica/core_extensions.rb', line 3

def to_query
  require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
  self.collect do |key, value|
    "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
  end.sort * '&'
end

#valueObject



14
15
16
# File 'lib/gattica/core_extensions.rb', line 14

def value
  self.values.first if self.length == 1
end