File tree 1 file changed +35
-12
lines changed
1 file changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -496,27 +496,50 @@ def include?(obj)
496
496
any? { |v | v == obj }
497
497
end
498
498
499
- def inject ( object = undefined , &block )
499
+ def inject ( object = undefined , sym = undefined , &block )
500
500
%x{
501
501
var result = object;
502
502
503
- self.$each._p = function() {
504
- var value = #{ Opal . destructure ( `arguments` ) } ;
503
+ if (block !== nil) {
504
+ self.$each._p = function() {
505
+ var value = #{ Opal . destructure ( `arguments` ) } ;
506
+
507
+ if (result === undefined) {
508
+ result = value;
509
+ return;
510
+ }
511
+
512
+ value = $opal.$yieldX(block, [result, value]);
513
+
514
+ if (value === $breaker) {
515
+ result = $breaker.$v;
516
+ return $breaker;
517
+ }
505
518
506
- if (result === undefined) {
507
519
result = value;
508
- return;
520
+ };
521
+ }
522
+ else {
523
+ if (sym === undefined) {
524
+ if (!#{ Symbol === object } ) {
525
+ #{ raise TypeError , "#{ object . inspect } is not a Symbol" } ;
526
+ }
527
+
528
+ sym = object;
529
+ result = undefined;
509
530
}
510
531
511
- value = $opal.$yieldX(block, [result, value]);
532
+ self.$each._p = function() {
533
+ var value = #{ Opal . destructure ( `arguments` ) } ;
512
534
513
- if (value === $breaker ) {
514
- result = $breaker.$v ;
515
- return $breaker ;
516
- }
535
+ if (result === undefined ) {
536
+ result = value ;
537
+ return ;
538
+ }
517
539
518
- result = value;
519
- };
540
+ result = #{ `result` . __send__ sym , `value` } ;
541
+ };
542
+ }
520
543
521
544
self.$each();
522
545
You can’t perform that action at this time.
0 commit comments