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 143 143 assert_equal %w(hello), hash.keys 144 144 end 145 145 146 def test_starts_ends_with 146 def test_starts_ends_with_alias 147 147 s = "hello" 148 148 assert s.starts_with?('h') 149 149 assert s.starts_with?('hel') 150 150 assert !s.starts_with?('el') 151 151 152 assert s.start_with?('h') 153 assert s.start_with?('hel') 154 assert !s.start_with?('el') 155 152 156 assert s.ends_with?('o') 153 157 assert s.ends_with?('lo') 154 158 assert !s.ends_with?('el') 159 160 assert s.end_with?('o') 161 assert s.end_with?('lo') 162 assert !s.end_with?('el') 155 163 end 156 164 157 165 # FIXME: Ruby 1.9 -
lib/active_support/core_ext/range/conversions.rb
old new 1 1 module ActiveSupport #:nodoc: 2 2 module CoreExtensions #:nodoc: 3 3 module Range #:nodoc: 4 # Getting dates in different convenient string representations and other objects4 # Getting ranges in different convenient string representations and other objects 5 5 module Conversions 6 DATE_FORMATS = {6 RANGE_FORMATS = { 7 7 :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } 8 8 } 9 9 … … 15 15 end 16 16 17 17 def to_formatted_s(format = :default) 18 DATE_FORMATS[format] ? DATE_FORMATS[format].call(first, last) : to_default_s18 RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s 19 19 end 20 20 end 21 21 end -
lib/active_support/core_ext/string.rb
old new 10 10 include ActiveSupport::CoreExtensions::String::Access 11 11 include ActiveSupport::CoreExtensions::String::Conversions 12 12 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 14 19 if defined? ActiveSupport::CoreExtensions::String::Iterators 15 20 include ActiveSupport::CoreExtensions::String::Iterators 16 21 end -
lib/active_support/core_ext/integer/even_odd.rb
old new 10 10 def multiple_of?(number) 11 11 self % number == 0 12 12 end 13 13 14 14 def even? 15 15 multiple_of? 2 16 end 17 16 end if RUBY_VERSION < '1.9' 17 18 18 def odd? 19 19 !even? 20 end 20 end if RUBY_VERSION < '1.9' 21 21 end 22 22 end 23 23 end -
lib/active_support/core_ext/string/starts_ends_with.rb
old new 3 3 module String #:nodoc: 4 4 # Additional string tests. 5 5 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 6 13 # Does the string start with the specified +prefix+? 7 14 def starts_with?(prefix) 8 15 prefix = prefix.to_s