Skip to content

Instantly share code, notes, and snippets.

@michaeldwan
Created April 20, 2010 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldwan/373052 to your computer and use it in GitHub Desktop.
Save michaeldwan/373052 to your computer and use it in GitHub Desktop.
class DirtyTrackingArray < Array
attr_accessor :dirty
def initialize
@dirty = false
end
def push(value)
@dirty = true
super
end
def <<(value)
@dirty = true
super
end
end
x = DirtyTrackingArray.new
puts x.dirty
x.push 'foo'
puts x.dirty
x << 'bar'
puts x.dirty
puts x.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment