Class: ArgvParser::IteratableArray
- Inherits:
-
Array
- Object
- Array
- ArgvParser::IteratableArray
- Defined in:
- lib/ruby-process-controller/argv_parser.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #current ⇒ Object
- #each_with_iterator ⇒ Object
- #end? ⇒ Boolean
-
#initialize(*args, &block) ⇒ IteratableArray
constructor
A new instance of IteratableArray.
- #look_ahead(offset = 1) ⇒ Object
- #remains ⇒ Object
- #slice_until! ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ IteratableArray
Returns a new instance of IteratableArray.
76 77 78 79 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 76 def initialize *args, &block @position = 0 super(*args, &block) end |
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
81 82 83 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 81 def position @position end |
Instance Method Details
#current ⇒ Object
117 118 119 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 117 def current self[@position] end |
#each_with_iterator ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 83 def each_with_iterator while @position < length result = yield(current) if result.kind_of?(Array) if result.first == :and_crop slice!(@position, result.last) elsif result.first == :after_slice_until! else step end else step end end end |
#end? ⇒ Boolean
133 134 135 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 133 def end? @position >= length end |
#look_ahead(offset = 1) ⇒ Object
121 122 123 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 121 def look_ahead(offset = 1) self[@position + offset] end |
#remains ⇒ Object
125 126 127 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 125 def remains slice(@position..-1) end |
#slice_until! ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 101 def slice_until! slice_from = @position step while @position < length break if yield(current) step end result = slice!(slice_from, @position - slice_from) @position = slice_from return result end |
#step ⇒ Object
129 130 131 |
# File 'lib/ruby-process-controller/argv_parser.rb', line 129 def step @position += 1 end |