@@ -64,7 +64,7 @@ def self.[](*objs)
64
64
65
65
def self . allocate
66
66
%x{
67
- var hash = new #{ self } ._alloc;
67
+ var hash = new self._alloc;
68
68
hash.map = {};
69
69
hash.keys = [];
70
70
return hash;
@@ -75,44 +75,44 @@ def initialize(defaults = undefined, &block)
75
75
%x{
76
76
if (defaults != null) {
77
77
if (defaults.constructor == Object) {
78
- var map = #{ self } .map, keys = #{ self } .keys;
78
+ var map = self.map, keys = self.keys;
79
79
80
80
for (var key in defaults) {
81
81
keys.push(key);
82
82
map[key] = defaults[key];
83
83
}
84
84
}
85
85
else {
86
- #{ self } .none = defaults;
86
+ self.none = defaults;
87
87
}
88
88
}
89
89
else if (block !== nil) {
90
- #{ self } .proc = block;
90
+ self.proc = block;
91
91
}
92
92
93
- return #{ self } ;
93
+ return self;
94
94
}
95
95
end
96
96
97
97
def ==( other )
98
98
%x{
99
- if (#{ self } === other) {
99
+ if (self === other) {
100
100
return true;
101
101
}
102
102
103
103
if (!other.map || !other.keys) {
104
104
return false;
105
105
}
106
106
107
- if (#{ self } .keys.length !== other.keys.length) {
107
+ if (self.keys.length !== other.keys.length) {
108
108
return false;
109
109
}
110
110
111
- var map = #{ self } .map,
111
+ var map = self.map,
112
112
map2 = other.map;
113
113
114
- for (var i = 0, length = #{ self } .keys.length; i < length; i++) {
115
- var key = #{ self } .keys[i], obj = map[key], obj2 = map2[key];
114
+ for (var i = 0, length = self.keys.length; i < length; i++) {
115
+ var key = self.keys[i], obj = map[key], obj2 = map2[key];
116
116
117
117
if (#{ `obj` != `obj2` } ) {
118
118
return false;
@@ -125,28 +125,28 @@ def ==(other)
125
125
126
126
def []( key )
127
127
%x{
128
- var map = #{ self } .map;
128
+ var map = self.map;
129
129
130
130
if ($hasOwn.call(map, key)) {
131
131
return map[key];
132
132
}
133
133
134
- var proc = #{ @proc } ;
134
+ var proc = #@proc ;
135
135
136
136
if (proc !== nil) {
137
137
return #{ `proc` . call self , key } ;
138
138
}
139
139
140
- return #{ @none } ;
140
+ return #@none ;
141
141
}
142
142
end
143
143
144
144
def []=( key , value )
145
145
%x{
146
- var map = #{ self } .map;
146
+ var map = self.map;
147
147
148
148
if (!$hasOwn.call(map, key)) {
149
- #{ self } .keys.push(key);
149
+ self.keys.push(key);
150
150
}
151
151
152
152
map[key] = value;
@@ -157,13 +157,13 @@ def []=(key, value)
157
157
158
158
def assoc ( object )
159
159
%x{
160
- var keys = #{ self } .keys, key;
160
+ var keys = self.keys, key;
161
161
162
162
for (var i = 0, length = keys.length; i < length; i++) {
163
163
key = keys[i];
164
164
165
165
if (#{ `key` == object } ) {
166
- return [key, #{ self } .map[key]];
166
+ return [key, self.map[key]];
167
167
}
168
168
}
169
169
@@ -173,9 +173,9 @@ def assoc(object)
173
173
174
174
def clear
175
175
%x{
176
- #{ self } .map = {};
177
- #{ self } .keys = [];
178
- return #{ self } ;
176
+ self.map = {};
177
+ self.keys = [];
178
+ return self;
179
179
}
180
180
end
181
181
@@ -185,13 +185,13 @@ def clone
185
185
186
186
result.map = {}; result.keys = [];
187
187
188
- var map = #{ self } .map,
188
+ var map = self.map,
189
189
map2 = result.map,
190
190
keys2 = result.keys;
191
191
192
- for (var i = 0, length = #{ self } .keys.length; i < length; i++) {
193
- keys2.push(#{ self } .keys[i]);
194
- map2[#{ self } .keys[i]] = map[#{ self } .keys[i]];
192
+ for (var i = 0, length = self.keys.length; i < length; i++) {
193
+ keys2.push(self.keys[i]);
194
+ map2[self.keys[i]] = map[self.keys[i]];
195
195
}
196
196
197
197
return result;
@@ -216,11 +216,11 @@ def default_proc=(proc)
216
216
217
217
def delete ( key )
218
218
%x{
219
- var map = #{ self } .map, result = map[key];
219
+ var map = self.map, result = map[key];
220
220
221
221
if (result != null) {
222
222
delete map[key];
223
- #{ self } .keys.$delete(key);
223
+ self.keys.$delete(key);
224
224
225
225
return result;
226
226
}
@@ -233,7 +233,7 @@ def delete_if(&block)
233
233
return enum_for :delete_if unless block
234
234
235
235
%x{
236
- var map = #{ self } .map, keys = #{ self } .keys, value;
236
+ var map = self.map, keys = self.keys, value;
237
237
238
238
for (var i = 0, length = keys.length; i < length; i++) {
239
239
var key = keys[i], obj = map[key];
@@ -251,7 +251,7 @@ def delete_if(&block)
251
251
}
252
252
}
253
253
254
- return #{ self } ;
254
+ return self;
255
255
}
256
256
end
257
257
@@ -281,7 +281,7 @@ def each_key(&block)
281
281
return enum_for :each_key unless block
282
282
283
283
%x{
284
- var keys = #{ self } .keys;
284
+ var keys = self.keys;
285
285
286
286
for (var i = 0, length = keys.length; i < length; i++) {
287
287
var key = keys[i];
@@ -291,7 +291,7 @@ def each_key(&block)
291
291
}
292
292
}
293
293
294
- return #{ self } ;
294
+ return self;
295
295
}
296
296
end
297
297
@@ -301,27 +301,27 @@ def each_value(&block)
301
301
return enum_for :each_value unless block
302
302
303
303
%x{
304
- var map = #{ self } .map, keys = #{ self } .keys;
304
+ var map = self.map, keys = self.keys;
305
305
306
306
for (var i = 0, length = keys.length; i < length; i++) {
307
307
if (block(map[keys[i]]) === $breaker) {
308
308
return $breaker.$v;
309
309
}
310
310
}
311
311
312
- return #{ self } ;
312
+ return self;
313
313
}
314
314
end
315
315
316
316
def empty?
317
- `#{ self } .keys.length === 0`
317
+ `self.keys.length === 0`
318
318
end
319
319
320
320
alias eql? ==
321
321
322
322
def fetch ( key , defaults = undefined , &block )
323
323
%x{
324
- var value = #{ self } .map[key];
324
+ var value = self.map[key];
325
325
326
326
if (value != null) {
327
327
return value;
@@ -347,7 +347,7 @@ def fetch(key, defaults = undefined, &block)
347
347
348
348
def flatten ( level = undefined )
349
349
%x{
350
- var map = #{ self } .map, keys = #{ self } .keys, result = [];
350
+ var map = self.map, keys = self.keys, result = [];
351
351
352
352
for (var i = 0, length = keys.length; i < length; i++) {
353
353
var key = keys[i], value = map[key];
@@ -372,13 +372,13 @@ def flatten(level=undefined)
372
372
end
373
373
374
374
def has_key? ( key )
375
- `$hasOwn.call(#{ self } .map, key)`
375
+ `$hasOwn.call(self.map, key)`
376
376
end
377
377
378
378
def has_value? ( value )
379
379
%x{
380
- for (var assoc in #{ self } .map) {
381
- if (#{ `#{ self } .map[assoc]` == value } ) {
380
+ for (var assoc in self.map) {
381
+ if (#{ `self.map[assoc]` == value } ) {
382
382
return true;
383
383
}
384
384
}
@@ -388,14 +388,14 @@ def has_value?(value)
388
388
end
389
389
390
390
def hash
391
- `#{ self } ._id`
391
+ `self._id`
392
392
end
393
393
394
394
alias include? has_key?
395
395
396
396
def index ( object )
397
397
%x{
398
- var map = #{ self } .map, keys = #{ self } .keys;
398
+ var map = self.map, keys = self.keys;
399
399
400
400
for (var i = 0, length = keys.length; i < length; i++) {
401
401
var key = keys[i];
@@ -411,7 +411,7 @@ def index(object)
411
411
412
412
def indexes ( *keys )
413
413
%x{
414
- var result = [], map = #{ self } .map, val;
414
+ var result = [], map = self.map, val;
415
415
416
416
for (var i = 0, length = keys.length; i < length; i++) {
417
417
var key = keys[i], val = map[key];
@@ -420,7 +420,7 @@ def indexes(*keys)
420
420
result.push(val);
421
421
}
422
422
else {
423
- result.push(#{ self } .none);
423
+ result.push(self.none);
424
424
}
425
425
}
426
426
@@ -432,12 +432,12 @@ def indexes(*keys)
432
432
433
433
def inspect
434
434
%x{
435
- var inspect = [], keys = #{ self } .keys, map = #{ self } .map;
435
+ var inspect = [], keys = self.keys, map = self.map;
436
436
437
437
for (var i = 0, length = keys.length; i < length; i++) {
438
438
var key = keys[i], val = map[key];
439
439
440
- if (val === #{ self } ) {
440
+ if (val === self) {
441
441
inspect.push(#{ `key` . inspect } + '=>' + '{...}');
442
442
} else {
443
443
inspect.push(#{ `key` . inspect } + '=>' + #{ `map[key]` . inspect } );
@@ -450,7 +450,7 @@ def inspect
450
450
451
451
def invert
452
452
%x{
453
- var result = $hash(), keys = #{ self } .keys, map = #{ self } .map,
453
+ var result = $hash(), keys = self.keys, map = self.map,
454
454
keys2 = result.keys, map2 = result.map;
455
455
456
456
for (var i = 0, length = keys.length; i < length; i++) {
@@ -468,7 +468,7 @@ def keep_if(&block)
468
468
return enum_for :keep_if unless block
469
469
470
470
%x{
471
- var map = #{ self } .map, keys = #{ self } .keys, value;
471
+ var map = self.map, keys = self.keys, value;
472
472
473
473
for (var i = 0, length = keys.length; i < length; i++) {
474
474
var key = keys[i], obj = map[key];
@@ -486,7 +486,7 @@ def keep_if(&block)
486
486
}
487
487
}
488
488
489
- return #{ self } ;
489
+ return self;
490
490
}
491
491
end
492
492
@@ -495,22 +495,18 @@ def keep_if(&block)
495
495
alias key? has_key?
496
496
497
497
def keys
498
- %x{
499
- return #{ self } .keys.slice(0);
500
- }
498
+ `self.keys.slice(0)`
501
499
end
502
500
503
501
def length
504
- %x{
505
- return #{ self } .keys.length;
506
- }
502
+ `self.keys.length`
507
503
end
508
504
509
505
alias member? has_key?
510
506
511
507
def merge ( other , &block )
512
508
%x{
513
- var keys = #{ self } .keys, map = #{ self } .map,
509
+ var keys = self.keys, map = self.map,
514
510
result = $hash(), keys2 = result.keys, map2 = result.map;
515
511
516
512
for (var i = 0, length = keys.length; i < length; i++) {
@@ -553,7 +549,7 @@ def merge(other, &block)
553
549
554
550
def merge! ( other , &block )
555
551
%x{
556
- var keys = #{ self } .keys, map = #{ self } .map,
552
+ var keys = self.keys, map = self.map,
557
553
keys2 = other.keys, map2 = other.map;
558
554
559
555
if (block === nil) {
@@ -581,13 +577,13 @@ def merge!(other, &block)
581
577
}
582
578
}
583
579
584
- return #{ self } ;
580
+ return self;
585
581
}
586
582
end
587
583
588
584
def rassoc ( object )
589
585
%x{
590
- var keys = #{ self } .keys, map = #{ self } .map;
586
+ var keys = self.keys, map = self.map;
591
587
592
588
for (var i = 0, length = keys.length; i < length; i++) {
593
589
var key = keys[i], obj = map[key];
@@ -605,7 +601,7 @@ def reject(&block)
605
601
return enum_for :reject unless block
606
602
607
603
%x{
608
- var keys = #{ self } .keys, map = #{ self } .map,
604
+ var keys = self.keys, map = self.map,
609
605
result = $hash(), map2 = result.map, keys2 = result.keys;
610
606
611
607
for (var i = 0, length = keys.length; i < length; i++) {
@@ -627,23 +623,23 @@ def reject(&block)
627
623
628
624
def replace ( other )
629
625
%x{
630
- var map = #{ self } .map = {}, keys = #{ self } .keys = [];
626
+ var map = self.map = {}, keys = self.keys = [];
631
627
632
628
for (var i = 0, length = other.keys.length; i < length; i++) {
633
629
var key = other.keys[i];
634
630
keys.push(key);
635
631
map[key] = other.map[key];
636
632
}
637
633
638
- return #{ self } ;
634
+ return self;
639
635
}
640
636
end
641
637
642
638
def select ( &block )
643
639
return enum_for :select unless block
644
640
645
641
%x{
646
- var keys = #{ self } .keys, map = #{ self } .map,
642
+ var keys = self.keys, map = self.map,
647
643
result = $hash(), map2 = result.map, keys2 = result.keys;
648
644
649
645
for (var i = 0, length = keys.length; i < length; i++) {
@@ -667,7 +663,7 @@ def select!(&block)
667
663
return enum_for :select! unless block
668
664
669
665
%x{
670
- var map = #{ self } .map, keys = #{ self } .keys, value, result = nil;
666
+ var map = self.map, keys = self.keys, value, result = nil;
671
667
672
668
for (var i = 0, length = keys.length; i < length; i++) {
673
669
var key = keys[i], obj = map[key];
@@ -682,7 +678,7 @@ def select!(&block)
682
678
683
679
length--;
684
680
i--;
685
- result = #{ self }
681
+ result = self
686
682
}
687
683
}
688
684
@@ -692,7 +688,7 @@ def select!(&block)
692
688
693
689
def shift
694
690
%x{
695
- var keys = #{ self } .keys, map = #{ self } .map;
691
+ var keys = self.keys, map = self.map;
696
692
697
693
if (keys.length) {
698
694
var key = keys[0], obj = map[key];
@@ -713,7 +709,7 @@ def shift
713
709
714
710
def to_a
715
711
%x{
716
- var keys = #{ self } .keys, map = #{ self } .map, result = [];
712
+ var keys = self.keys, map = self.map, result = [];
717
713
718
714
for (var i = 0, length = keys.length; i < length; i++) {
719
715
var key = keys[i];
@@ -756,26 +752,13 @@ def to_n
756
752
757
753
alias update merge!
758
754
759
- def value? ( value )
760
- %x{
761
- var map = #{ self } .map;
762
-
763
- for (var assoc in map) {
764
- var v = map[assoc];
765
- if (#{ `v` == value } ) {
766
- return true;
767
- }
768
- }
769
-
770
- return false;
771
- }
772
- end
755
+ alias value? has_value?
773
756
774
757
alias values_at indexes
775
758
776
759
def values
777
760
%x{
778
- var map = #{ self } .map,
761
+ var map = self.map,
779
762
result = [];
780
763
781
764
for (var key in map) {
0 commit comments