Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created February 24, 2010 16:41
Show Gist options
  • Save pjb3/313597 to your computer and use it in GitHub Desktop.
Save pjb3/313597 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