Class: Remap::Selector::Index
- Inherits:
-
Unit
- Object
- Unit
- Remap::Selector::Index
- Defined in:
- lib/remap/selector/index.rb
Overview
Selects value at given index
Instance Method Summary collapse
-
#call(outer_state) {|| ... } ⇒ State<U>
Selects the #indexth element from state and passes it to block.
- #index ⇒ Integer
Instance Method Details
#call(outer_state) {|| ... } ⇒ State<U>
Selects the #indexth element from state and passes it to block
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/remap/selector/index.rb', line 27 def call(outer_state, &block) return call(outer_state, &:itself) unless block outer_state.bind(index: index) do |array, state| requirement[array] do state.fatal!("Expected array but got %p (%s)", array, array.class) end element = array.fetch(index) do state.ignore!("Index %s in array %p (%s) not found", index, array, array.class) end state.set(element, index: index).then(&block) end end |
#index ⇒ Integer
15 |
# File 'lib/remap/selector/index.rb', line 15 attribute :index, Integer |