Module: HashHelper
- Defined in:
- app/helpers/hash_helper.rb
Instance Method Summary collapse
-
#get_value(key, hash, default_value = nil) ⇒ Object
Returns a specific value from the given hash (or the default value if not set).
-
#pop_value(key, hash, default_value = nil) ⇒ Object
Removes and returns a specific value from the given hash (or the default value if not set).
-
#symbolize_keys(hash) ⇒ Object
all keys of the given hash symbolize.
Instance Method Details
#get_value(key, hash, default_value = nil) ⇒ Object
Returns a specific value from the given hash (or the default value if not set).
7 8 9 10 11 |
# File 'app/helpers/hash_helper.rb', line 7 def get_value(key, hash, default_value = nil) value = hash.delete key value = default_value if value.nil? and !default_value.nil? value end |
#pop_value(key, hash, default_value = nil) ⇒ Object
Removes and returns a specific value from the given hash (or the default value if not set).
14 15 16 17 |
# File 'app/helpers/hash_helper.rb', line 14 def pop_value(key, hash, default_value = nil) symbolize_keys hash unless hash.empty? get_value key.to_sym, hash, default_value end |
#symbolize_keys(hash) ⇒ Object
all keys of the given hash symbolize.
20 21 22 23 24 |
# File 'app/helpers/hash_helper.rb', line 20 def symbolize_keys(hash) result = {} hash.each { |key, value| result[key.to_sym] = value } hash.replace result end |