Class: Hash
Instance Method Summary collapse
Instance Method Details
#clean ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/awein/hash.rb', line 18 def clean each do |k, v| if v.is_a?(Hash) v.clean elsif v.to_s.empty? delete(k) end end end |
#evaluate(*args) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/awein/hash.rb', line 2 def evaluate(*args) = {:default => nil}.merge(args.last.is_a?(Hash) ? args.pop : {}) target = self # Initial target is self. while target && key = args.shift target = target[key] end return target if target return [:default] end |
#get(*keys) ⇒ Object
13 14 15 16 |
# File 'lib/awein/hash.rb', line 13 def get(*keys) return nil if keys.blank? self.fetch keys.shift, self.get(*keys) end |
#symbolize_keys_recursive ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/awein/hash.rb', line 28 def symbolize_keys_recursive inject({}) do |, (key, value)| value = value.symbolize_keys_recursive if value.instance_of? Hash value = value.symbolize_keys_recursive if value.instance_of? Array [key.to_sym || key] = value end end |