Class: Hash
- Defined in:
- lib/jss/compatibility.rb,
lib/jss/ruby_extensions/hash.rb
Instance Method Summary collapse
-
#jss_nillify!(to_nils = '', recurse = false) {|value| ... } ⇒ Hash
Convert Hash values to nil.
Instance Method Details
#jss_nillify!(to_nils = '', recurse = false) {|value| ... } ⇒ Hash
Convert Hash values to nil.
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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jss/ruby_extensions/hash.rb', line 60 def jss_nillify!(to_nils = '', recurse = false, &block ) nillify_these = [] << to_nils nillify_these.flatten! self.each_pair do |k,v| if v.class == 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 |