Created
January 4, 2012 06:34
-
-
Save sj26/1558806 to your computer and use it in GitHub Desktop.
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
a = [] | |
def a.<< e | |
super.tap do | |
puts "Adding #{e.inspect}" | |
end | |
end | |
a << 1 | |
# Adding 1 | |
# => [1] | |
class Blah | |
def initialize | |
@a = [] | |
def @a.<< e | |
super.tap do | |
puts "Adding #{e.inspect}" | |
end | |
end | |
end | |
end | |
blah = Blah.new | |
blah.instance_eval do | |
@a << 2 | |
end | |
# Adding 2 | |
# => [2] | |
class User | |
module ProductArrayMixin | |
def << e | |
super.tap do | |
puts "Adding #{e.inspect}" | |
end | |
end | |
end | |
attr_reader :products | |
def initialize | |
@products = [] | |
@products.extend ProductArrayMixin | |
end | |
end | |
user = User.new | |
user.products << 3 | |
# Adding 3 | |
# => [3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment