Class: Croesus::Coercion
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.
71 72 73 74 75 |
# File 'lib/croesus/coerce.rb', line 71 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
80 81 82 |
# File 'lib/croesus/coerce.rb', line 80 def call(object) @block.call(object, @target) end |