Module: Flexcon
- Defined in:
- lib/flexcon.rb,
lib/flexcon/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .argnames(handler) ⇒ Object
- .args(scope, handler, *props) ⇒ Object
- .dispatch(scope, handler, *props) ⇒ Object
Class Method Details
.argnames(handler) ⇒ Object
22 23 24 |
# File 'lib/flexcon.rb', line 22 def argnames(handler) handler.parameters.map { |a| a[-1] } end |
.args(scope, handler, *props) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/flexcon.rb', line 9 def args(scope, handler, *props) props = self.argnames(handler) if props.empty? getter = lambda do |index| scope[props[index]] end if scope.is_a?(Hash) getter ||= lambda do |index| scope[index] end if scope.is_a?(Array) getter ||= lambda do |index| scope.send(props[index]) end limit = handler.arity limit = props.size if limit == -1 return (0...limit).map(&getter) end |
.dispatch(scope, handler, *props) ⇒ Object
5 6 7 |
# File 'lib/flexcon.rb', line 5 def dispatch(scope, handler, *props) handler.call(*self.args(scope, handler, *props)) end |