Sha256: 619ecd04ec451363ed769117d3c38785b99f9764b75fbb1922ed84a37c340c01
Contents?: true
Size: 484 Bytes
Versions: 2
Compression:
Stored size: 484 Bytes
Contents
class Hash def merge_and_incr(hash) self.clone.merge_and_incr!(hash) end def merge_and_incr!(hash) raise ArgumentError unless hash.is_a?(Hash) hash.each do |key, value| self[key] = value unless self.set_or_incr(key, value) end self end def set_or_incr(key, value) return false unless value.is_a?(Numeric) self[key] = 0 unless self.has_key?(key) return false unless self[key].is_a?(Numeric) self[key] += value true end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
redistat-0.5.0 | lib/redistat/core_ext/hash.rb |
redistat-0.4.0 | lib/redistat/core_ext/hash.rb |