Ticket #7136: hash.diff
| File hash.diff, 1.4 kB (added by mislav, 2 years ago) |
|---|
-
test/unit/hash.html
old new 63 63 64 64 new Test.Unit.Runner({ 65 65 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 66 76 testKeys: function(){ with(this) { 67 77 assertEnumEqual([], $H({}).keys()) 68 78 assertEnumEqual(['a'], $H(Fixtures.one).keys()) -
src/hash.js
old new 1 1 var Hash = function(obj) { 2 Object.extend(this, obj || {}); 2 if (obj && obj.constructor == Hash) this.merge(obj); 3 else Object.extend(this, obj || {}); 3 4 }; 4 5 5 6 Object.extend(Hash, { … … 13 14 var values = pair.value.compact(); 14 15 if (values.length < 2) pair.value = values.reduce(); 15 16 else { 16 key = encodeURIComponent(pair.key);17 key = encodeURIComponent(pair.key); 17 18 values.each(function(value) { 18 19 value = value != undefined ? encodeURIComponent(value) : ''; 19 20 parts.push(key + '=' + encodeURIComponent(value));