Class: CoercibleString

Inherits:
String show all
Defined in:
lib/aliyun/oss/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#previous, #previous!, #remove_extended, #remove_extended!, #tap, #to_header, #underscore, #valid_utf8?

Class Method Details

.coerce(string) ⇒ Object



102
103
104
# File 'lib/aliyun/oss/extensions.rb', line 102

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

Instance Method Details

#coerceObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/aliyun/oss/extensions.rb', line 107

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