module Nuggets::Hash::SeenMixin

Public Instance Methods

seen([seen[, unseen]]) → aHash click to toggle source

Returns a hash that returns unseen as the default value for a key that wasn't seen before and seen for a key that was.

Examples:

hash = Hash.seen
hash[:foo]  #=> false
hash[:foo]  #=> true
hash[:foo]  #=> true
hash[:bar]  #=> false
hash[:bar]  #=> true

hash = Hash.seen(42, 23)
hash[:foo]  #=> 23
hash[:foo]  #=> 42
hash[:foo]  #=> 42
hash[:bar]  #=> 23
hash[:bar]  #=> 42
   # File lib/nuggets/hash/seen_mixin.rb
52 def seen(seen = true, unseen = false)
53   new { |hash, key| hash[key] = seen; unseen }
54 end