Class: Extant::Coercers::Symbol

Inherits:
Base
  • Object
show all
Defined in:
lib/extant/coercers/symbol.rb

Constant Summary

Constants inherited from Base

Base::UncoercedValue

Instance Method Summary collapse

Methods inherited from Base

#coerced?, coercer_name, #initialize

Constructor Details

This class inherits a constructor from Extant::Coercers::Base

Instance Method Details

#coerceObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/extant/coercers/symbol.rb', line 3

def coerce
  return UncoercedValue if value == nil

  if value.is_a?(::String)
    result = value.to_sym
  elsif value.is_a?(::Symbol)
    result = value
  else
    raise ArgumentError
  end

  self.coerced = true
  result
rescue ArgumentError
  UncoercedValue
end