Class: Iteration
- Inherits:
-
Object
- Object
- Iteration
- Defined in:
- lib/iteration.rb
Overview
Iteration encapsulates a step in an each loop.
Instance Attribute Summary collapse
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#prior ⇒ Object
readonly
Returns the value of attribute prior.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#__step__(value, &block) ⇒ Object
TODO: For Ruby 1.9 make private and use fcall ?.
- #after ⇒ Object
- #first? ⇒ Boolean
-
#initialize(enum) ⇒ Iteration
constructor
A new instance of Iteration.
- #last? ⇒ Boolean
Constructor Details
#initialize(enum) ⇒ Iteration
Returns a new instance of Iteration.
12 13 14 15 16 17 |
# File 'lib/iteration.rb', line 12 def initialize(enum) @enum = enum @index = 0 @value = nil @prior = [] end |
Instance Attribute Details
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
10 11 12 |
# File 'lib/iteration.rb', line 10 def enum @enum end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/iteration.rb', line 10 def index @index end |
#prior ⇒ Object (readonly)
Returns the value of attribute prior.
10 11 12 |
# File 'lib/iteration.rb', line 10 def prior @prior end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/iteration.rb', line 10 def value @value end |
Instance Method Details
#__step__(value, &block) ⇒ Object
TODO: For Ruby 1.9 make private and use fcall ?
35 36 37 38 39 40 |
# File 'lib/iteration.rb', line 35 def __step__(value, &block) @value = value block.call @index += 1 @prior << value end |
#after ⇒ Object
27 28 29 |
# File 'lib/iteration.rb', line 27 def after enum.slice(index+1..-1) end |
#first? ⇒ Boolean
19 20 21 |
# File 'lib/iteration.rb', line 19 def first? index == 0 end |
#last? ⇒ Boolean
23 24 25 |
# File 'lib/iteration.rb', line 23 def last? index+1 == enum.size end |