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

Ticket #7136: hash.diff

File hash.diff, 1.4 kB (added by mislav, 2 years ago)
  • test/unit/hash.html

    old new  
    6363   
    6464  new Test.Unit.Runner({ 
    6565     
     66    testConstruct: function(){ with(this) { 
     67      var h = $H(Fixtures.one) 
     68      assertNotIdentical(Fixtures.one, h) 
     69      assertIdentical(h, $H(h)) 
     70 
     71      var h2 = new Hash(h) 
     72      assertNotIdentical(h, h2) 
     73      assertEqual(h.inspect(), h2.inspect()) 
     74    }}, 
     75     
    6676    testKeys: function(){ with(this) { 
    6777      assertEnumEqual([],               $H({}).keys()) 
    6878      assertEnumEqual(['a'],            $H(Fixtures.one).keys()) 
  • src/hash.js

    old new  
    11var Hash = function(obj) { 
    2   Object.extend(this, obj || {}); 
     2  if (obj && obj.constructor == Hash) this.merge(obj); 
     3  else Object.extend(this, obj || {}); 
    34}; 
    45 
    56Object.extend(Hash, { 
     
    1314        var values = pair.value.compact(); 
    1415        if (values.length < 2) pair.value = values.reduce(); 
    1516        else { 
    16                key = encodeURIComponent(pair.key); 
     17          key = encodeURIComponent(pair.key); 
    1718          values.each(function(value) { 
    1819            value = value != undefined ? encodeURIComponent(value) : ''; 
    1920            parts.push(key + '=' + encodeURIComponent(value));