Class: Parameters::Types::Proc

Inherits:
Type show all
Defined in:
lib/parameters/types/proc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#<, #<=, #==, ===, #===, coerce, #to_ruby, to_ruby

Constructor Details

#initialize(callback) ⇒ Proc

Creates a new Proc type.

Parameters:

  • callback (#call)

    The callback that will handle the actual coercion.



16
17
18
# File 'lib/parameters/types/proc.rb', line 16

def initialize(callback)
  @callback = callback
end

Instance Attribute Details

#callbackObject (readonly)

The callback that will coerce values



8
9
10
# File 'lib/parameters/types/proc.rb', line 8

def callback
  @callback
end

Instance Method Details

#coerce(value) ⇒ ::Object

Coerces the value using the callback.

Parameters:

  • value (::Object)

    The value to coerce.

Returns:

  • (::Object)

    The result of the callback.



29
30
31
# File 'lib/parameters/types/proc.rb', line 29

def coerce(value)
  @callback.call(value)
end