Created
January 4, 2012 06:00
-
-
Save lantins/1558714 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
class User | |
attr_accessor :products | |
def initialize | |
@products = ProductsArray.new | |
end | |
end | |
class ProductsArray < Array | |
def <<(obj) | |
super(obj) | |
puts "you've pushed an object onto the array" | |
end | |
end | |
usr = User.new | |
usr.products << 'test' | |
p usr |
Aha! I wouldn't of known that, thanks =)
Link to docs: http://ruby-doc.org/core-1.9.3/Object.html#method-i-tap
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should probably use:
so
products << 1 << 2
still works, etc.