diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 6a243fe982..af277f9995 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -28,6 +28,10 @@ class String 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? diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index d9702dd9ff..affa1b5e18 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -110,6 +110,14 @@ class StringInflectionsTest < Test::Unit::TestCase 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) |