Module: JamfRubyExtensions::Hash::Utils
- Included in:
- Hash
- Defined in:
- lib/jamf/ruby_extensions/hash/utils.rb
Instance Method Summary collapse
-
#j_nillify!(to_nils = '', recurse = false) {|value| ... } ⇒ Hash
(also: #jss_nillify!)
Convert Hash values to nil.
Instance Method Details
#j_nillify!(to_nils = '', recurse = false) {|value| ... } ⇒ Hash Also known as: jss_nillify!
Convert Hash values to nil. This is useful in the Classic API due to lack of consistency as to whether unset values come to us as nils or empty strings. This APIObject class converts all empty strings to nils using this method.
With no block, values equalling the String, or any member of the Array, given will be converted to nil. Equality is evaluated with == and Array#include?
With a block, if the result of the block evaluates to true, the value is converted to nil.
Subhashes are ignored unless recurse is true.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jamf/ruby_extensions/hash/utils.rb', line 87 def j_nillify!(to_nils = '', recurse = false, &block) nillify_these = [] << to_nils nillify_these.flatten! each_pair do |k, v| if v.instance_of?(Hash) v.jss_nillify!(to_nils, recurse, &block) next end do_it = if block_given? yield v else nillify_these.include? v end self[k] = nil if do_it end # each pair end |