Ruby 1.9 compat: 'a'.ord == 'a'[0]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8403 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
aa4ad404c6
commit
6d5ee8dab3
@ -5,6 +5,11 @@ module CoreExtensions #: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})
|
||||
|
@ -78,6 +78,11 @@ def test_humanize
|
||||
end
|
||||
end
|
||||
|
||||
def test_ord
|
||||
assert_equal 97, 'a'.ord
|
||||
assert_equal 97, 'abc'.ord
|
||||
end
|
||||
|
||||
def test_string_to_time
|
||||
assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time
|
||||
assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local)
|
||||
|
Loading…
Reference in New Issue
Block a user