Class: Remap::Selector::Key
- Inherits:
-
Unit
- Object
- Unit
- Remap::Selector::Key
- Defined in:
- lib/remap/selector/key.rb
Overview
Selects value at key from state
Instance Method Summary collapse
-
#call(outer_state) {|| ... } ⇒ State<U>
Selects #key from state and passes it to block.
-
#key ⇒ #hash
#hash.
Instance Method Details
#call(outer_state) {|| ... } ⇒ State<U>
Selects #key from state and passes it to block
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/remap/selector/key.rb', line 30 def call(outer_state, &block) unless block_given? raise ArgumentError, "The key selector requires an iteration block" end outer_state.bind(key: key) do |hash, state| requirement[hash] do state.fatal!("Expected hash but got %p (%s)", hash, hash.class) end value = hash.fetch(key) do state.ignore!("Key %p (%s) not found in hash %p (%s)", key, key.class, hash, hash.class) end state.set(value, key: key).then(&block) end end |