Created
February 24, 2010 16:41
-
-
Save pjb3/313597 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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