./lib/clean-hash/hash_pollute.rb in clean-hash-0.4.1 vs ./lib/clean-hash/hash_pollute.rb in clean-hash-0.5.0

- old
+ new

@@ -12,36 +12,15 @@ Marshal.load(Marshal.dump(self)) end def to_ch mode=nil if mode.is_a?(Array) - for key in keys - raise ArgumentError, 'CleanHash key "%s" not allowed' % key unless mode.include?(key) - end - - for key in mode - self[key] = nil unless key?(key) - end - - ::CleanHash::OptsHash.new self + mode.each { |el| self[el] = nil if self[el].nil? } + ::CleanHash.create_struct self else - supported = %i{safe mutex strict} - raise ArgumentError, 'Unsupported type "%s", supported: %s' % [mode, supported] if mode && !supported.include?(mode) - - if mode == :mutex - ::CleanHash::MutexHash.new self - else - ::CleanHash.new self, mode - end + mode ||= :indifferent + ::CleanHash.create mode, self end - end - end - - ::Array.class_eval do - # coverts keys to empty hash methods and returns read_only hash - def to_ch strict=false - hash = inject({}) { |h, key| h[key] = nil; h } - ::CleanHash::OptsHash.new hash end end end end