Class: Hash
Overview
:nodoc:
Instance Method Summary collapse
-
#get_list(sym_or_string, default = nil) ⇒ Object
Gets the given key as an array.
-
#get_value(sym_or_string, default = nil) ⇒ Object
Gets the value from the Hash, regardless if it’s stored with a symbol or a key as a string.
Instance Method Details
#get_list(sym_or_string, default = nil) ⇒ Object
Gets the given key as an array. If it’s already an array, it will be returned, otherwise we’ll check if it’s a comma-separated list. The default will be processed in the same way as if was read from the Hash.
186 187 188 189 190 191 192 193 |
# File 'lib/watchdogger.rb', line 186 def get_list(sym_or_string, default = nil) value = get_value(sym_or_string, default) return value if(value.is_a?(Array)) assit(value.is_a?(String) || value.is_a?(Symbol)) value = value.to_s.split(',').collect do |val| val.strip end end |
#get_value(sym_or_string, default = nil) ⇒ Object
Gets the value from the Hash, regardless if it’s stored with a symbol or a key as a string. You may supply a default value - if the default is set to false, the method will raise an argument error. By default, it will return nil if the element isn’t found.
177 178 179 180 181 |
# File 'lib/watchdogger.rb', line 177 def get_value(sym_or_string, default = nil) value = self[sym_or_string.to_s] || self[sym_or_string.to_sym] || default raise(ArgumentError, "No value set for #{sym_or_string}") if((default == false) && !value) value end |