Module: CMDx::Coercions::Coerce
Overview
Invokes an inline ‘:coerce` handler (Symbol method name, Proc, or anything with `#call`). Used by #coerce for non-built-in rules.
Instance Method Summary collapse
-
#call(task, value, handler) ⇒ Object
The handler’s return value.
Instance Method Details
#call(task, value, handler) ⇒ Object
Returns the handler’s return value.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cmdx/coercions/coerce.rb', line 17 def call(task, value, handler) case handler when ::Symbol task.send(handler, value) when ::Proc task.instance_exec(value, &handler) else return handler.call(value, task) if handler.respond_to?(:call) raise ArgumentError, "coerce handler must be a Symbol, Proc, or respond to #call" end end |