Skip to content

Instantly share code, notes, and snippets.

@jerhinesmith
Created June 2, 2011 21:55
Show Gist options
  • Select an option

  • Save jerhinesmith/1005423 to your computer and use it in GitHub Desktop.

Select an option

Save jerhinesmith/1005423 to your computer and use it in GitHub Desktop.
Simple dirty? flag
class Percent
attr_reader :finished
attr_accessor :dirty
def finished=(value)
self.dirty = true
@finished = value
end
def dirty?
!!dirty
end
def initialize(attributes = {})
self.finished = attributes[:finished] || 0
self.dirty = false
end
end
p = Percent.new(:finished => 10)
puts p.finished
#=> 10
puts p.dirty?
#=> false
p.finished = 20
puts p.finished
#=> 20
puts p.dirty?
#=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment