Class: Clive::Option::Runner
- Inherits:
-
Object
- Object
- Clive::Option::Runner
- Extended by:
- StateActions
- Defined in:
- lib/clive/option/runner.rb
Overview
Runner is a class which is used for executing blocks given to Options and Commands. It allows you to inside blocks;
-
reference arguments by name (instead of using block params)
-
get values from the state hash
-
set value to the state hash
-
update values in the state hash
Class Method Summary collapse
- ._run(args, state, fn) ⇒ Object
-
.method_missing(sym, *args) ⇒ Object
Allows arguments passed in to be referenced directly by name.
Methods included from StateActions
Class Method Details
._run(args, state, fn) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/clive/option/runner.rb', line 133 def _run(args, state, fn) return unless fn # order of this doesn't matter as it will just be accessed by key @args = Hash[args] @state = state if fn.arity > 0 # Remember to use the ordered array version instance_exec(*args.map {|i| i.last }, &fn) else instance_exec(&fn) end @state end |
.method_missing(sym, *args) ⇒ Object
Allows arguments passed in to be referenced directly by name.
152 153 154 155 156 157 158 |
# File 'lib/clive/option/runner.rb', line 152 def method_missing(sym, *args) if @args.has_key?(sym) @args[sym] else super end end |