module CounterContainer
Provides counting functionality for @counter. Affords incrementation, decrementation and resetting the count via convenient methods.
For this module to work, @counter and @start_val are assumed to be of type Integer.
Constants
- COUNTING_INSTANCE_OBJECT_IS_NIL
- COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER
- START_VAL_INSTANCE_OBJECT_IS_NIL
- START_VAL_INSTANCE_OBJECT_IS_NON_INTEGER
Attributes
counter[W]
sets @counter, the object holding the value of the current count
start_val[W]
sets @start_val, the default value of the counter
Public Instance Methods
count()
click to toggle source
Gets the current count. @return [Integer] a duplicate of @counter
# File lib/counter_container.rb, line 49 def count raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil? raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer @counter end
dec!()
click to toggle source
Synonymous method for CounterContainer#increment!
# File lib/counter_container.rb, line 40 def dec! raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil? raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer decrement! end
decrement!()
click to toggle source
Decrements @counter by Integer value of 1
# File lib/counter_container.rb, line 35 def decrement! @counter -= 1 end
inc!()
click to toggle source
Synonymous method for CounterContainer#increment!
# File lib/counter_container.rb, line 30 def inc! increment! end
increment!()
click to toggle source
Increments @counter by Integer value of 1
# File lib/counter_container.rb, line 22 def increment! raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil? raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer @counter += 1 end
reset!()
click to toggle source
Resets the value of @counter to @basis
# File lib/counter_container.rb, line 56 def reset! raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil? raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer raise START_VAL_INSTANCE_OBJECT_IS_NIL if @start_val.nil? raise START_VAL_INSTANCE_OBJECT_IS_NON_INTEGER if @start_val.class != Integer @counter = @start_val.dup end