Class: Counter
- Inherits:
-
Object
- Object
- Counter
- Defined in:
- counter.rb
Overview
Note:
This is only a minimal example
Implements a simple accumulator, whose value is accessed via the attribute counter. Calling the method Counter#inc increments this value.
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
The current value of the count.
Instance Method Summary collapse
-
#inc ⇒ Integer
increment the current value of the count.
-
#initialize(initial_value = 0) ⇒ Counter
constructor
create a new Counter with the given initial value.
Constructor Details
#initialize(initial_value = 0) ⇒ Counter
create a new Counter with the given initial value
15 16 17 |
# File 'counter.rb', line 15 def initialize(initial_value = 0) @counter = initial_value end |
Instance Attribute Details
#counter ⇒ Object (readonly)
The current value of the count
10 11 12 |
# File 'counter.rb', line 10 def counter @counter end |
Instance Method Details
#inc ⇒ Integer
increment the current value of the count
23 24 25 |
# File 'counter.rb', line 23 def inc @counter += 1 end |