Class: Yukata::Coercion

Inherits:
Object
  • Object
show all
Defined in:
lib/yukata/coercion.rb

Overview

This wraps the block that is provided when you register a coercion.

Author:

  • Matthew A. Johnston

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



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

Returns:

  • (Object)


20
21
22
# File 'lib/yukata/coercion.rb', line 20

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