Class: Whitespace::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/whitespace/data_structures/counter.rb

Instance Method Summary collapse

Constructor Details

#initializeCounter

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

#incrementObject



7
8
9
# File 'lib/whitespace/data_structures/counter.rb', line 7

def increment
  @value += 1
end

#to_intObject



20
21
22
# File 'lib/whitespace/data_structures/counter.rb', line 20

def to_int
  @value
end