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

Changeset 8402

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

Ruby 1.9 compat: shadowed vars, kcode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/multibyte/chars.rb

    r6882 r8402  
    120120      # +utf8_pragma+ checks if it can send this string to the handlers. It makes sure @string isn't nil and $KCODE is 
    121121      # set to 'UTF8'. 
    122       def utf8_pragma? 
    123         !@string.nil? && ($KCODE == 'UTF8') 
     122      if RUBY_VERSION < '1.9' 
     123        def utf8_pragma? 
     124          !@string.nil? && ($KCODE == 'UTF8') 
     125        end 
     126      else 
     127        def utf8_pragma? 
     128          !@string.nil? && (Encoding.default_external == Encoding::UTF_8) 
     129        end 
    124130      end 
    125131  end 
  • trunk/activesupport/test/core_ext/hash_ext_test.rb

    r8332 r8402  
    146146    assert_equal updated_with_mixed['b'], 2 
    147147 
    148     assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? {|hash| hash.keys.size == 2
     148    assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? { |h| h.keys.size == 2
    149149  end 
    150150 
     
    372372 
    373373  def test_one_level_with_yielding 
    374     xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |xml
    375       xml.creator("Rails") 
     374    xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |x
     375      x.creator("Rails") 
    376376    end 
    377377 
  • trunk/activesupport/test/core_ext/module/attribute_aliasing_test.rb

    r7195 r8402  
    44  class Content 
    55    attr_accessor :title, :Data 
    6    
     6 
     7    def initialize 
     8      @title, @Data = nil, nil 
     9    end 
     10 
    711    def title? 
    812      !title.nil? 
    913    end 
    10      
     14 
    1115    def Data? 
    1216      !self.Data.nil? 
  • trunk/activesupport/test/json/encoding_test.rb

    r8255 r8402  
    5454 
    5555  def test_utf8_string_encoded_properly_when_kcode_is_utf8 
    56     old_kcode, $KCODE = $KCODE, 'UTF8' 
    57     assert_equal '"\\u20ac2.99"', '€2.99'.to_json 
    58     assert_equal '"\\u270e\\u263a"', '✎☺'.to_json 
    59   ensure 
    60     $KCODE = old_kcode 
     56    with_kcode 'UTF8' do 
     57      assert_equal '"\\u20ac2.99"', '€2.99'.to_json 
     58      assert_equal '"\\u270e\\u263a"', '✎☺'.to_json 
     59    end 
    6160  end 
    6261 
     
    8180 
    8281  protected 
     82    def with_kcode(code) 
     83      if RUBY_VERSION < '1.9' 
     84        begin 
     85          old_kcode, $KCODE = $KCODE, 'UTF8' 
     86          yield 
     87        ensure 
     88          $KCODE = old_kcode 
     89        end 
     90      else 
     91        yield 
     92      end 
     93    end 
     94 
    8395    def object_keys(json_object) 
    8496      json_object[1..-2].scan(/([^{}:,\s]+):/).flatten.sort