Class: Greentable::Counter
- Inherits:
-
Object
- Object
- Greentable::Counter
- Defined in:
- lib/greentable/greentable_counter.rb
Instance Method Summary collapse
- #even? ⇒ Boolean
- #first? ⇒ Boolean
- #i ⇒ Object
- #inc ⇒ Object
-
#initialize(size) ⇒ Counter
constructor
A new instance of Counter.
- #last? ⇒ Boolean
- #odd? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(size) ⇒ Counter
Returns a new instance of Counter.
3 4 5 6 |
# File 'lib/greentable/greentable_counter.rb', line 3 def initialize(size) @i = 0 @max = size end |
Instance Method Details
#even? ⇒ Boolean
32 33 34 |
# File 'lib/greentable/greentable_counter.rb', line 32 def even? @i%2==1 end |
#first? ⇒ Boolean
16 17 18 |
# File 'lib/greentable/greentable_counter.rb', line 16 def first? @i == 0 end |
#i ⇒ Object
8 9 10 |
# File 'lib/greentable/greentable_counter.rb', line 8 def i @i end |
#inc ⇒ Object
24 25 26 |
# File 'lib/greentable/greentable_counter.rb', line 24 def inc @i += 1 end |
#last? ⇒ Boolean
20 21 22 |
# File 'lib/greentable/greentable_counter.rb', line 20 def last? @i >= (@max-1) end |
#odd? ⇒ Boolean
28 29 30 |
# File 'lib/greentable/greentable_counter.rb', line 28 def odd? @i%2==0 end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/greentable/greentable_counter.rb', line 12 def to_s @i.to_s end |