Class: Whitespace::Counter
- Inherits:
-
Object
- Object
- Whitespace::Counter
- Defined in:
- lib/whitespace/data_structures/counter.rb
Instance Method Summary collapse
- #change_to(new_value) ⇒ Object
- #increment ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #to_int ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
3 4 5 |
# File 'lib/whitespace/data_structures/counter.rb', line 3 def initialize @value = 0 end |
Instance Method Details
#change_to(new_value) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/whitespace/data_structures/counter.rb', line 11 def change_to(new_value) new_value = new_value.to_i if new_value >= 0 @value = new_value else raise ArgumentError, "must be non-negative: #{new_value}" end end |
#increment ⇒ Object
7 8 9 |
# File 'lib/whitespace/data_structures/counter.rb', line 7 def increment @value += 1 end |
#to_int ⇒ Object
20 21 22 |
# File 'lib/whitespace/data_structures/counter.rb', line 20 def to_int @value end |