Class: Greentable::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/greentable/greentable_counter.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/greentable/greentable_counter.rb', line 32

def even?
  @i%2==1
end

#first?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/greentable/greentable_counter.rb', line 16

def first?
  @i == 0
end

#iObject



8
9
10
# File 'lib/greentable/greentable_counter.rb', line 8

def i
  @i
end

#incObject



24
25
26
# File 'lib/greentable/greentable_counter.rb', line 24

def inc
  @i += 1
end

#last?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/greentable/greentable_counter.rb', line 20

def last?
  @i >= (@max-1)
end

#odd?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/greentable/greentable_counter.rb', line 28

def odd?
  @i%2==0
end

#to_sObject



12
13
14
# File 'lib/greentable/greentable_counter.rb', line 12

def to_s
  @i.to_s
end