Added getbyte as a core_ext to Ruby < 1.9

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Santiago Pastorino 2010-06-27 13:08:38 -03:00 committed by José Valim
parent 0c0b0aa0f2
commit fa96638bf2
2 changed files with 12 additions and 0 deletions

@ -28,6 +28,10 @@ def ord
self[0]
end unless method_defined?(:ord)
def getbyte(index)
self[index]
end if RUBY_VERSION < '1.9'
# Form can be either :utc (default) or :local.
def to_time(form = :utc)
return nil if self.blank?

@ -110,6 +110,14 @@ def test_ord
assert_equal 97, 'abc'.ord
end
if RUBY_VERSION < '1.9'
def test_getbyte
assert_equal 97, 'a'.getbyte(0)
assert_equal 99, 'abc'.getbyte(2)
assert_nil 'abc'.getbyte(3)
end
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)