Created
June 2, 2011 21:55
-
-
Save jerhinesmith/1005423 to your computer and use it in GitHub Desktop.
Simple dirty? flag
This file contains hidden or 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 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