Class: BinderCore::Compiler::Iterator
- Inherits:
-
Object
- Object
- BinderCore::Compiler::Iterator
- Defined in:
- lib/binder_core/compiler.rb
Overview
:nodoc:
Instance Method Summary collapse
- #count ⇒ Object
- #has_next? ⇒ Boolean
- #init(collection) ⇒ Object
-
#initialize(collection = nil) ⇒ Iterator
constructor
A new instance of Iterator.
- #next ⇒ Object
- #replace(new_val) ⇒ Object
Constructor Details
#initialize(collection = nil) ⇒ Iterator
Returns a new instance of Iterator.
58 59 60 |
# File 'lib/binder_core/compiler.rb', line 58 def initialize(collection=nil) init collection unless collection.nil? end |
Instance Method Details
#count ⇒ Object
83 84 85 |
# File 'lib/binder_core/compiler.rb', line 83 def count @que.length end |
#has_next? ⇒ Boolean
79 80 81 |
# File 'lib/binder_core/compiler.rb', line 79 def has_next? @step < count-1 end |
#init(collection) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/binder_core/compiler.rb', line 62 def init(collection) @collection = collection @keys = [] @que = [] @step = -1 if collection.is_a? Array collection.length.times { |n| @keys << n } @que = collection.dup elsif collection.is_a? Hash collection.keys.each do |key| @keys << key @que << collection[key] end end end |
#next ⇒ Object
87 88 89 90 |
# File 'lib/binder_core/compiler.rb', line 87 def next @step += 1 @que[@step] end |
#replace(new_val) ⇒ Object
92 93 94 |
# File 'lib/binder_core/compiler.rb', line 92 def replace(new_val) @collection[@keys[@step]] = new_val end |