Sha256: ff6bb55d07494c5bd441a40e4dac9f3ef9831855a24a56cb08b5853eaef20f9a
Contents?: true
Size: 772 Bytes
Versions: 1
Compression:
Stored size: 772 Bytes
Contents
class CleanHash def self.pollute! ::Hash.class_eval do # merge but to not overwrite keys def deep_merge hash klass = ::CleanHash::DeepMerge klass[deep_clone].deep_merge klass[hash] end # true clone of the hash with 0 references to the old one def deep_clone Marshal.load(Marshal.dump(self)) end def to_ch mode=nil if mode.is_a?(Array) if not_alowed = (keys - mode).first raise ArgumentError.new('CleanHash option "%s" is not alowed (%s)' % [not_alowed, mode.join(', ')]) end mode.each { |el| self[el] = nil if self[el].nil? } CleanHash.create_struct self else CleanHash.new self end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clean-hash-0.6.0 | ./lib/clean-hash/hash_pollute.rb |