Class: Croesus::Coercion

Inherits:
Object show all
Defined in:
lib/croesus/coerce.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

Constructor Details

#initialize(origin, target, &block) ⇒ Coercion

Returns a new instance of Coercion.

Parameters:

  • origin (Class)

    the class that the object is

  • target (Class)

    the class you wish to coerce to



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

Returns:



80
81
82
# File 'lib/croesus/coerce.rb', line 80

def call(object)
  @block.call(object, @target)
end