Skip to content

Instantly share code, notes, and snippets.

@rrichards
Forked from pjb3/hash_spy.rb
Created March 21, 2010 01:19
Show Gist options
  • Save rrichards/339012 to your computer and use it in GitHub Desktop.
Save rrichards/339012 to your computer and use it in GitHub Desktop.
class HashSpy
def initialize(hash={})
@hash = hash
end
def method_missing(method_name, *args, &block)
puts "***** hash access"
puts " before: #{@hash.inspect}"
r = @hash.send(method_name, *args, &block)
puts " after: #{@hash.inspect}"
puts " backtrace:\n #{caller.join("\n ")}"
r
end
end
IMPORTANT_STUFF = HashSpy.new(
:password => "too many secrets"
)
def change_password(h)
h[:password] = "FAIL"
end
def print_password
puts IMPORTANT_STUFF[:password]
end
print_password
change_password(IMPORTANT_STUFF)
print_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment