Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/bitbucket_rest_api/core_ext/hash.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
-
#all_keys ⇒ Object
:nodoc:.
-
#except(*items) ⇒ Object
:nodoc:.
-
#except!(*keys) ⇒ Object
:nodoc:.
- #has_deep_key?(key) ⇒ Boolean
-
#serialize ⇒ Object
:nodoc:.
-
#symbolize_keys ⇒ Object
:nodoc:.
-
#symbolize_keys! ⇒ Object
:nodoc:.
Instance Method Details
#all_keys ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 41 def all_keys # :nodoc: keys = self.keys keys.each do |key| if self[key].is_a?(Hash) keys << self[key].all_keys.compact.flatten next end end keys.flatten end |
#except(*items) ⇒ Object
:nodoc:
3 4 5 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 3 def except(*items) # :nodoc: self.dup.except!(*items) end |
#except!(*keys) ⇒ Object
:nodoc:
7 8 9 10 11 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 7 def except!(*keys) # :nodoc: copy = self.dup keys.each { |key| copy.delete!(key) } copy end |
#has_deep_key?(key) ⇒ Boolean
52 53 54 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 52 def has_deep_key?(key) self.all_keys.include? key end |
#serialize ⇒ Object
:nodoc:
37 38 39 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 37 def serialize # :nodoc: self.map { |key, val| [key, val].join("=") }.join("&") end |
#symbolize_keys ⇒ Object
:nodoc:
13 14 15 16 17 18 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 13 def symbolize_keys # :nodoc: inject({}) do |hash, (key, value)| hash[(key.to_sym rescue key) || key] = value hash end end |
#symbolize_keys! ⇒ Object
:nodoc:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bitbucket_rest_api/core_ext/hash.rb', line 20 def symbolize_keys! # :nodoc: hash = symbolize_keys hash.each do |key, val| hash[key] = case val when Hash val.symbolize_keys! when Array val.map do |item| item.is_a?(Hash) ? item.symbolize_keys! : item end else val end end return hash end |