Class: Accumulators::Count

Inherits:
Object
  • Object
show all
Defined in:
lib/accumulators/count.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCount

Returns a new instance of Count.



5
6
7
# File 'lib/accumulators/count.rb', line 5

def initialize
  @count = 0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



3
4
5
# File 'lib/accumulators/count.rb', line 3

def count
  @count
end

Instance Method Details

#add(rhs) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/accumulators/count.rb', line 9

def add(rhs)
  if rhs.is_a? Accumulators::Count
    @count += rhs.count
  else
    @count += 1
  end
end