Class: Hash

Inherits:
Object show all
Defined in:
lib/waw/ext/core/hash.rb

Instance Method Summary collapse

Instance Method Details

#forget(*keys) ⇒ Object



15
16
17
# File 'lib/waw/ext/core/hash.rb', line 15

def forget(*keys)
  self.dup.delete_if{|k,v| keys.flatten.include?(k)}
end

#forget!(*keys) ⇒ Object



11
12
13
# File 'lib/waw/ext/core/hash.rb', line 11

def forget!(*keys)
  self.delete_if{|k,v| keys.flatten.include?(k)}
end

#keep(*keys) ⇒ Object



7
8
9
# File 'lib/waw/ext/core/hash.rb', line 7

def keep(*keys)
  self.dup.delete_if{|k,v| !keys.flatten.include?(k)}
end

#keep!(*keys) ⇒ Object



3
4
5
# File 'lib/waw/ext/core/hash.rb', line 3

def keep!(*keys)
  self.delete_if{|k,v| !keys.flatten.include?(k)}
end

#methodizeObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/waw/ext/core/hash.rb', line 25

def methodize
  copy = self.symbolize_keys
  keys.each {|key| 
    copy.instance_eval <<-EOF
      def #{key}
        self[:"#{key}"]
      end
    EOF
  }
  copy
end

#symbolize_keysObject



19
20
21
22
23
# File 'lib/waw/ext/core/hash.rb', line 19

def symbolize_keys
  copy = Hash.new
  self.each_pair {|k,v| copy[k.to_s.to_sym] = v}
  copy
end

#to_url_queryObject



43
44
45
# File 'lib/waw/ext/core/hash.rb', line 43

def to_url_query
  ::Rack::Utils.build_query(self)
end

#unsymbolize_keysObject



37
38
39
40
41
# File 'lib/waw/ext/core/hash.rb', line 37

def unsymbolize_keys
  copy = Hash.new
  self.each_pair {|k,v| copy[k.to_s] = v}
  copy
end