Class: Shrink::Wrap::Property::Coercion::Class

Inherits:
Object
  • Object
show all
Includes:
Support::TypeCheck
Defined in:
lib/shrink/wrap/property/coercion/class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::TypeCheck

#ensure_callable!, #ensure_type!

Constructor Details

#initialize(klass) ⇒ Class

Returns a new instance of Class.



12
13
14
15
# File 'lib/shrink/wrap/property/coercion/class.rb', line 12

def initialize(klass)
  ensure_type!(::Class, klass)
  self.klass = klass
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



10
11
12
# File 'lib/shrink/wrap/property/coercion/class.rb', line 10

def klass
  @klass
end

Instance Method Details

#coerce(data) ⇒ Object



17
18
19
20
21
22
# File 'lib/shrink/wrap/property/coercion/class.rb', line 17

def coerce(data)
  return klass.shrink_wrap(data) if klass.respond_to?(:shrink_wrap)
  return klass.coerce(data) if klass.respond_to?(:coerce)

  klass.new(data)
end