Ruby hash delegator that tracks which keys were accessed
class TrackedHash < SimpleDelegator | |
attr_reader :accessed_keys | |
def initialize(hash) | |
super | |
@accessed_keys = Set.new | |
end | |
def [](key) | |
@accessed_keys << key | |
super | |
end | |
def fetch(*args) | |
@accessed_keys << args[0] | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment