Changeset 8397
- Timestamp:
- 12/15/07 02:27:11 (5 months ago)
- Files:
-
- trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/range/conversions.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/string.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/string_ext_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/integer/even_odd.rb
r1863 r8397 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 trunk/activesupport/lib/active_support/core_ext/range/conversions.rb
r7474 r8397 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 } … … 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 trunk/activesupport/lib/active_support/core_ext/string.rb
r7773 r8397 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 trunk/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
r2176 r8397 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) trunk/activesupport/test/core_ext/string_ext_test.rb
r8199 r8397 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') … … 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