Class: Parameters::Types::Class

Inherits:
Object show all
Defined in:
lib/parameters/types/class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Object

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

Methods inherited from Type

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

Constructor Details

#initialize(base_class) ⇒ Class

Initializes the Class Type.

Parameters:

  • base_class (Class)

    The base-class to wrap all values within.



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

def initialize(base_class)
  @base_class = base_class
end

Instance Attribute Details

#base_classObject (readonly)

The base-class of the Class Type



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

def base_class
  @base_class
end

Instance Method Details

#coerce(value) ⇒ Object

Coerces a value into an instance of the Class.

Parameters:

  • value (Object)

    The value to coerce.

Returns:

  • (Object)

    The instance of the Class, created using the value.



39
40
41
# File 'lib/parameters/types/class.rb', line 39

def coerce(value)
  @base_class.new(value)
end

#to_rubyClass

The Ruby Class the type represents.

Returns:

  • (Class)

    The base-class of the Class Type.



26
27
28
# File 'lib/parameters/types/class.rb', line 26

def to_ruby
  @base_class
end