Module: ActiveSupport::CoreExtensions::String::Conversions
- Defined in:
- lib/rails_appengine/active_support_conversions.rb
Overview
Converting strings to other objects
Instance Method Summary collapse
-
#ord ⇒ Object
‘a’.ord == ‘a’ for Ruby 1.9 forward compatibility.
- #to_date ⇒ Object
- #to_datetime ⇒ Object
-
#to_time(form = :utc) ⇒ Object
Form can be either :utc (default) or :local.
Instance Method Details
#ord ⇒ Object
‘a’.ord == ‘a’ for Ruby 1.9 forward compatibility.
9 10 11 |
# File 'lib/rails_appengine/active_support_conversions.rb', line 9 def ord self[0] end |
#to_date ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rails_appengine/active_support_conversions.rb', line 22 def to_date begin ::Date.new(*::Date._parse(self, false). values_at(:year, :mon, :mday)) rescue nil end end |
#to_datetime ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_appengine/active_support_conversions.rb', line 30 def to_datetime begin ::DateTime.civil(*::Date._parse(self, false). values_at(:year, :mon, :mday, :hour, :min, :sec). map { |arg| arg || 0 }) rescue nil end end |
#to_time(form = :utc) ⇒ Object
Form can be either :utc (default) or :local.
13 14 15 16 17 18 19 20 21 |
# File 'lib/rails_appengine/active_support_conversions.rb', line 13 def to_time(form = :utc) begin ::Time.send("#{form}_time", *::Date._parse(self, false). values_at(:year, :mon, :mday, :hour, :min, :sec). map { |arg| arg || 0 }) rescue nil end end |