Sha256: 3a0b0eea878c7709e01994f0c6dcb4bc78775f185d54e3fe901c67387467690e
Contents?: true
Size: 969 Bytes
Versions: 6
Compression:
Stored size: 969 Bytes
Contents
=begin rdoc Hash extentions =end class Hash alias :old_select :select def select(&block) Hash[*self.old_select(&block).inject([]){|res,(k,v)| res << k << v}] end def extract!(&block) o = select(&block) o.keys.each {|k| self.delete(k) } o end def append(other_hash) returning Hash.new do |h| h.merge!(self) other_hash.each do |k,v| h[k] = has_key?(k) ? [self[k], v].flatten : v end end end def append!(other_hash) other_hash.each do |k,v| self[k] = has_key?(k) ? [self[k], v].flatten : v end self end def safe_merge(other_hash) merge(other_hash.delete_if {|k,v| has_key?(k) }) end def safe_merge!(other_hash) merge!(other_hash.delete_if {|k,v| has_key?(k) && !v.nil? }) end def flush_out(pre="", post="") map {|k,v| "#{pre}#{k} => #{v.to_option_string}#{post}"} end def to_os m={} each {|k,v| m[k] = v.to_os } MyOpenStruct.new(m) end end
Version data entries
6 entries across 6 versions & 2 rubygems