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

Changeset 6882

Show
Ignore:
Timestamp:
05/28/07 23:33:54 (1 year ago)
Author:
bitsweat
Message:

Multibyte strings respond_to the String methods they proxy so they can be duck-typed. Closes #6549.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r6858 r6882  
    11*SVN* 
     2 
     3* Multibyte strings respond_to the String methods they proxy so they can be duck-typed.  #6549 [Tuxie] 
    24 
    35* Array#to_xml yields the builder just like Hash and ActiveRecord::Base.  #8472 [seth] 
     
    147149* Make String#chars slicing behaviour consistent with String. Closes #6387 [Manfred Stienstra] 
    148150 
    149 * Pull in latest multibye patch. Closes #6346 [Manfred Stienstra] 
     151* Pull in latest multibyte patch. Closes #6346 [Manfred Stienstra] 
    150152 
    151153* Add ActiveSupport::Multibyte.  Provides String#chars which lets you deal with strings as a sequence of chars, not of bytes. Closes #6242 [Julian Tarkhanov, Manfred Stienstra, Thijs van der Vossen & Jan Behrens] 
  • trunk/activesupport/lib/active_support/multibyte/chars.rb

    r6571 r6882  
    4040      # core dumps. Don't go there. 
    4141      @string 
     42    end 
     43     
     44    # Make duck-typing with String possible 
     45    def respond_to?(method) 
     46      super || @string.respond_to?(method) || handler.respond_to?(method) || 
     47        (method.to_s =~ /(.*)!/ && handler.respond_to?($1)) || false 
    4248    end 
    4349     
  • trunk/activesupport/test/multibyte_chars_test.rb

    r5224 r6882  
    152152  end 
    153153   
     154  def test_duck_typing 
     155    assert_equal true,  'test'.chars.respond_to?(:strip) 
     156    assert_equal true,  'test'.chars.respond_to?(:normalize) 
     157    assert_equal true,  'test'.chars.respond_to?(:normalize!) 
     158    assert_equal false, 'test'.chars.respond_to?(:a_method_that_doesnt_exist) 
     159  end 
     160   
    154161  protected 
    155162