Class: CoercibleString

Inherits:
String
  • Object
show all
Defined in:
lib/aliyun/ess/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#camelize, #remove_extended, #remove_extended!, #underscore, #valid_utf8?

Class Method Details

.coerce(string) ⇒ Object



43
44
45
# File 'lib/aliyun/ess/extensions.rb', line 43

def coerce(string)
  new(string).coerce
end

Instance Method Details

#coerceObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aliyun/ess/extensions.rb', line 48

def coerce
  case self
  when 'true';         true
  when 'false';         false
  # Don't coerce numbers that start with zero
  when  /^[1-9]+\d*$/;   Integer(self)
  when datetime_format; Time.parse(self)
  else
    self
  end
end