Class: Tenjin::HtmlTagHelper::Cycle
- Inherits:
-
Object
- Object
- Tenjin::HtmlTagHelper::Cycle
- Defined in:
- lib/tenjin.rb
Overview
cycle values everytime when #to_s() is called ex:
cycle = Cycle.new('odd', 'even')
"#{cycle}" #=> 'odd'
"#{cycle}" #=> 'even'
"#{cycle}" #=> 'odd'
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(*values) ⇒ Cycle
constructor
A new instance of Cycle.
- #next ⇒ Object (also: #to_s)
Constructor Details
#initialize(*values) ⇒ Cycle
Returns a new instance of Cycle.
167 168 169 170 171 |
# File 'lib/tenjin.rb', line 167 def initialize(*values) @values = values.freeze @length = values.length @index = -1 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
172 173 174 |
# File 'lib/tenjin.rb', line 172 def index @index end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
166 167 168 |
# File 'lib/tenjin.rb', line 166 def values @values end |
Instance Method Details
#count ⇒ Object
177 178 179 |
# File 'lib/tenjin.rb', line 177 def count @index + 1 end |
#next ⇒ Object Also known as: to_s
173 174 175 |
# File 'lib/tenjin.rb', line 173 def next return @values[(@index += 1) % @length] end |