Class: Hash
Instance Method Summary collapse
- #forget(*keys) ⇒ Object
- #forget!(*keys) ⇒ Object
- #keep(*keys) ⇒ Object
- #keep!(*keys) ⇒ Object
- #methodize ⇒ Object
- #symbolize_keys ⇒ Object
- #to_url_query ⇒ Object
- #unsymbolize_keys ⇒ Object
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 |
#methodize ⇒ Object
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_keys ⇒ Object
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 |