Class: Cl::Cast::Cast

Inherits:
Struct
  • Object
show all
Defined in:
lib/cl/cast.rb

Constant Summary collapse

TRUE =
/^(true|yes|on)$/
FALSE =
/^(false|no|off)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



3
4
5
# File 'lib/cl/cast.rb', line 3

def opts
  @opts
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/cl/cast.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



3
4
5
# File 'lib/cl/cast.rb', line 3

def value
  @value
end

Instance Method Details

#applyObject



7
8
9
10
11
12
# File 'lib/cl/cast.rb', line 7

def apply
  return send(type) if respond_to?(type, true)
  raise ArgumentError, "Unknown type: #{type}"
rescue ::ArgumentError => e
  raise ArgumentError.new(:wrong_type, value.inspect, type)
end