Class: RPiet::Cycle
- Inherits:
-
Object
- Object
- RPiet::Cycle
- Defined in:
- lib/rpiet/cycle.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #decr(amount = 1) ⇒ Object
- #delta(other) ⇒ Object
- #incr(amount = 1) ⇒ Object
-
#initialize(value, name, list) ⇒ Cycle
constructor
A new instance of Cycle.
- #to_initial ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(value, name, list) ⇒ Cycle
Returns a new instance of Cycle.
5 6 7 |
# File 'lib/rpiet/cycle.rb', line 5 def initialize(value, name, list) @value, @name, @list = value, name.to_s.downcase, list end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rpiet/cycle.rb', line 3 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/rpiet/cycle.rb', line 3 def value @value end |
Instance Method Details
#+(other) ⇒ Object
17 18 19 |
# File 'lib/rpiet/cycle.rb', line 17 def +(other) @list[(@value + other.value) % @list.length] end |
#-(other) ⇒ Object
13 14 15 |
# File 'lib/rpiet/cycle.rb', line 13 def -(other) @list[(@value - other.value) % @list.length] end |
#decr(amount = 1) ⇒ Object
25 26 27 |
# File 'lib/rpiet/cycle.rb', line 25 def decr(amount = 1) @list[(@value - amount) % @list.length] end |
#delta(other) ⇒ Object
9 10 11 |
# File 'lib/rpiet/cycle.rb', line 9 def delta(other) (@value - other.value) % @list.length end |
#incr(amount = 1) ⇒ Object
21 22 23 |
# File 'lib/rpiet/cycle.rb', line 21 def incr(amount = 1) @list[(@value + amount) % @list.length] end |
#to_initial ⇒ Object
29 30 31 |
# File 'lib/rpiet/cycle.rb', line 29 def to_initial @name[0] end |
#to_s ⇒ Object Also known as: inspect
33 34 35 |
# File 'lib/rpiet/cycle.rb', line 33 def to_s "#{@name}(#{@value})" end |