Last active
December 19, 2015 12:49
-
-
Save tessi/5957491 to your computer and use it in GitHub Desktop.
Observe Hash#[]=
This file contains 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 SnakeHash < SimpleDelegator | |
def []=(arg1, arg2) | |
puts "!!1!" | |
@delegate_sd_obj[arg1] = arg2 | |
end | |
end | |
#[2] pry(main)> h = SnakeHash.new(Hash.new) | |
#=> {} | |
#[3] pry(main)> h[2] | |
#=> nil | |
#[4] pry(main)> h[2] = :foo | |
#!!1! | |
#=> :foo |
This file contains 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 FakeHash < Hash | |
def []=(arg1,arg2) | |
puts "!!!1!" | |
super | |
end | |
end | |
#[6] pry(main)> i = FakeHash.new | |
#=> {} | |
#[7] pry(main)> i[1] | |
#=> nil | |
#[8] pry(main)> i[1] = 3 | |
#!!!1! | |
#=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment