Class: Yukata::Coercion
- Inherits:
-
Object
- Object
- Yukata::Coercion
- Defined in:
- lib/yukata/coercion.rb
Overview
This wraps the block that is provided when you register a coercion.
Constant Summary collapse
- PASS_THROUGH =
Just passes the object on through
->(obj, _) { obj }
Instance Method Summary collapse
-
#call(object) ⇒ Object
Calls the coercion.
-
#initialize(origin, target, &block) ⇒ Coercion
constructor
A new instance of Coercion.
Constructor Details
#initialize(origin, target, &block) ⇒ Coercion
Returns a new instance of Coercion.
11 12 13 14 15 |
# File 'lib/yukata/coercion.rb', line 11 def initialize(origin, target, &block) @origin = origin @target = target @block = block_given? ? block : PASS_THROUGH end |
Instance Method Details
#call(object) ⇒ Object
Calls the coercion
20 21 22 |
# File 'lib/yukata/coercion.rb', line 20 def call(object) @block.call(object, @target) end |