module MasterView # this hash is designed to track modified times of its values # this behaviour is only supported through using []= and store # mechanisms and thus default semantics have been excluded # other update methods such as merge! have been excluded from # this implementation and will raise errors class MTimeTrackingHash < Hash # MTimeTrackingHash does not support defaults and thus does # not take default object or block def initialize super @mtimes = {} end def []=(key, value) update_mtime(key) super end def store(key, value) update_mtime(key) super end # returns the Time object for this key def mtime(key) @mtimes[key] end private def update_mtime(key) @mtimes[key] = Time.now end def default=(obj); raise "Not implemented"; end def merge!(obj,&block); raise "Not implemented"; end def reject!(obj,&block); raise "Not implemented"; end def replace(obj); raise "Not implemented"; end end end