Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8403

Show
Ignore:
Timestamp:
12/15/07 02:28:32 (10 months ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: 'a'.ord == 'a'[0]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/core_ext/string/conversions.rb

    r8199 r8403  
    66      # Converting strings to other objects 
    77      module Conversions 
     8        # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility. 
     9        def ord 
     10          self[0] 
     11        end if RUBY_VERSION < '1.9' 
     12 
    813        # Form can be either :utc (default) or :local. 
    914        def to_time(form = :utc) 
     
    1419          ::Date.new(*ParseDate.parsedate(self)[0..2]) 
    1520        end 
    16          
     21 
    1722        def to_datetime 
    1823          ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0) 
  • trunk/activesupport/test/core_ext/string_ext_test.rb

    r8397 r8403  
    7777      assert_equal(human, underscore.humanize) 
    7878    end 
     79  end 
     80 
     81  def test_ord 
     82    assert_equal 97, 'a'.ord 
     83    assert_equal 97, 'abc'.ord 
    7984  end 
    8085