Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/screenplay/datatype-extensions.rb
Overview
Adds a few extra methods to the standard Hash
Instance Method Summary collapse
-
#remove_nil_values! ⇒ Object
Removes all nil values from the hash.
-
#stringify_keys!(recursive = true) ⇒ Object
Changes all keys to strings.
-
#symbolize_keys!(recursive = true) ⇒ Object
Changes all keys to symbols.
Instance Method Details
#remove_nil_values! ⇒ Object
Removes all nil values from the hash. If the value is an array or hash, it will do this recursively.
84 85 86 87 |
# File 'lib/screenplay/datatype-extensions.rb', line 84 def remove_nil_values! self.compact! self.each { |val| val.remove_nil_values! if (val.is_a?(Hash) || val.is_a?(Array)) } end |
#stringify_keys!(recursive = true) ⇒ Object
Changes all keys to strings. If the value is an array or hash, it will do this recursively.
95 96 97 |
# File 'lib/screenplay/datatype-extensions.rb', line 95 def stringify_keys!(recursive = true) self.map! { |val| val.stringify_keys! if (recursive && (val.is_a?(Hash) || val.is_a?(Array))); val } end |
#symbolize_keys!(recursive = true) ⇒ Object
Changes all keys to symbols. If the value is an array or hash, it will do this recursively.
90 91 92 |
# File 'lib/screenplay/datatype-extensions.rb', line 90 def symbolize_keys!(recursive = true) self.map! { |val| val.symbolize_keys! if (recursive && (val.is_a?(Hash) || val.is_a?(Array))); val } end |