diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-15 02:28:32 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-15 02:28:32 +0000 |
commit | 6d5ee8dab37f7cb4a15ab7a3c4369b105055570e (patch) | |
tree | cd2557a03e5c89f03b10984465b05e0c54af6e1f /activesupport/lib/active_support/core_ext/string/conversions.rb | |
parent | aa4ad404c6aa4feccc69b8d7222bcfd1b1903215 (diff) | |
download | rails-6d5ee8dab37f7cb4a15ab7a3c4369b105055570e.tar.gz rails-6d5ee8dab37f7cb4a15ab7a3c4369b105055570e.tar.bz2 rails-6d5ee8dab37f7cb4a15ab7a3c4369b105055570e.zip |
Ruby 1.9 compat: 'a'.ord == 'a'[0]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8403 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 48d3f6d91d..663ea8747b 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -5,6 +5,11 @@ module ActiveSupport #:nodoc: module String #:nodoc: # Converting strings to other objects module Conversions + # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility. + def ord + self[0] + end if RUBY_VERSION < '1.9' + # Form can be either :utc (default) or :local. def to_time(form = :utc) ::Time.send("#{form}_time", *ParseDate.parsedate(self)[0..5].map {|arg| arg || 0}) @@ -13,11 +18,11 @@ module ActiveSupport #:nodoc: def to_date ::Date.new(*ParseDate.parsedate(self)[0..2]) end - + def to_datetime ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0) end end end end -end
\ No newline at end of file +end |