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

Ticket #1689: core_ext_1.9_compat.diff

File core_ext_1.9_compat.diff, 3.8 kB (added by chuyeow, 7 months ago)
  • test/core_ext/string_ext_test.rb

    old new  
    143143    assert_equal %w(hello), hash.keys 
    144144  end 
    145145 
    146   def test_starts_ends_with 
     146  def test_starts_ends_with_alias 
    147147    s = "hello" 
    148148    assert s.starts_with?('h') 
    149149    assert s.starts_with?('hel') 
    150150    assert !s.starts_with?('el') 
    151151 
     152    assert s.start_with?('h') 
     153    assert s.start_with?('hel') 
     154    assert !s.start_with?('el') 
     155 
    152156    assert s.ends_with?('o') 
    153157    assert s.ends_with?('lo') 
    154158    assert !s.ends_with?('el') 
     159 
     160    assert s.end_with?('o') 
     161    assert s.end_with?('lo') 
     162    assert !s.end_with?('el') 
    155163  end 
    156164 
    157165  # FIXME: Ruby 1.9 
  • lib/active_support/core_ext/range/conversions.rb

    old new  
    11module ActiveSupport #:nodoc: 
    22  module CoreExtensions #:nodoc: 
    33    module Range #:nodoc: 
    4       # Getting dates in different convenient string representations and other objects 
     4      # Getting ranges in different convenient string representations and other objects 
    55      module Conversions 
    6         DATE_FORMATS = { 
     6        RANGE_FORMATS = { 
    77          :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } 
    88        } 
    99 
     
    1515        end 
    1616 
    1717        def to_formatted_s(format = :default) 
    18           DATE_FORMATS[format] ? DATE_FORMATS[format].call(first, last) : to_default_s    
     18          RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s    
    1919        end 
    2020      end 
    2121    end 
  • lib/active_support/core_ext/string.rb

    old new  
    1010  include ActiveSupport::CoreExtensions::String::Access 
    1111  include ActiveSupport::CoreExtensions::String::Conversions 
    1212  include ActiveSupport::CoreExtensions::String::Inflections 
    13   include ActiveSupport::CoreExtensions::String::StartsEndsWith 
     13  if RUBY_VERSION < '1.9' 
     14    include ActiveSupport::CoreExtensions::String::StartsEndsWith 
     15  else 
     16    alias starts_with? start_with? 
     17    alias ends_with? end_with? 
     18  end 
    1419  if defined? ActiveSupport::CoreExtensions::String::Iterators 
    1520    include ActiveSupport::CoreExtensions::String::Iterators 
    1621  end 
  • lib/active_support/core_ext/integer/even_odd.rb

    old new  
    1010        def multiple_of?(number) 
    1111          self % number == 0 
    1212        end 
    13          
     13 
    1414        def even? 
    1515          multiple_of? 2 
    16         end 
    17          
     16        end if RUBY_VERSION < '1.9' 
     17 
    1818        def odd? 
    1919          !even? 
    20         end 
     20        end if RUBY_VERSION < '1.9' 
    2121      end 
    2222    end 
    2323  end 
  • lib/active_support/core_ext/string/starts_ends_with.rb

    old new  
    33    module String #:nodoc: 
    44      # Additional string tests. 
    55      module StartsEndsWith 
     6        def self.included(base) 
     7          base.class_eval do 
     8            alias_method :start_with?, :starts_with? 
     9            alias_method :end_with?, :ends_with? 
     10          end 
     11        end 
     12 
    613        # Does the string start with the specified +prefix+? 
    714        def starts_with?(prefix) 
    815          prefix = prefix.to_s