red 4.0.6 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +4 -3
- data/bin/red +1 -0
- data/lib/red/executable.rb +4 -1
- data/lib/red/nodes/assignment_nodes.rb +6 -5
- data/lib/red/nodes/call_nodes.rb +23 -8
- data/lib/red/nodes/control_nodes.rb +4 -9
- data/lib/red/nodes/data_nodes.rb +8 -6
- data/lib/red/nodes/definition_nodes.rb +14 -6
- data/lib/red/nodes/literal_nodes.rb +1 -1
- data/lib/red/nodes/logic_nodes.rb +14 -8
- data/lib/red/version.rb +2 -2
- data/lib/red.rb +10 -2
- data/lib/source/ruby.rb +387 -334
- data/spec/array.red +389 -0
- data/spec/hash.red +137 -0
- data/spec/object.red +22 -0
- data/spec/string.red +74 -0
- metadata +7 -6
- data/spec/red_spec.rb +0 -10
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -10
data/lib/source/ruby.rb
CHANGED
@@ -29,6 +29,14 @@
|
|
29
29
|
};
|
30
30
|
},
|
31
31
|
|
32
|
+
donateConstantsToClass: function(donor,recipient,overwrite) {
|
33
|
+
for(var x in donor) {
|
34
|
+
if(x.slice(0,2)==='c$' && (overwrite || recipient[x]===undefined)) {
|
35
|
+
recipient[x]=donor[x];
|
36
|
+
};
|
37
|
+
};
|
38
|
+
},
|
39
|
+
|
32
40
|
updateChildren: function(parentClass) {
|
33
41
|
for(var x in parentClass.__children__) {
|
34
42
|
var childClass=Red.inferConstantFromString(x);
|
@@ -54,7 +62,7 @@
|
|
54
62
|
newClass.__children__ = {};
|
55
63
|
newClass.__class__ = c$Class;
|
56
64
|
newClass.prototype.__class__=newClass;
|
57
|
-
Red.donateMethodsToSingleton(c$Class.prototype,newClass,true)
|
65
|
+
Red.donateMethodsToSingleton(c$Class.prototype,newClass,true);
|
58
66
|
},
|
59
67
|
|
60
68
|
interpretNamespace: function(longName) {
|
@@ -70,53 +78,49 @@
|
|
70
78
|
},
|
71
79
|
|
72
80
|
_module: function(longName,block){
|
73
|
-
var newModule,context=Red.interpretNamespace(longName),namespace=context[0],name=context[1];
|
74
|
-
if(namespace[
|
75
|
-
|
81
|
+
var newModule,context=Red.interpretNamespace(longName),namespace=context[0],name=context[1],c$name='c$'+name;
|
82
|
+
if(namespace[c$name]) {
|
83
|
+
if(namespace[c$name].m$class&&namespace[c$name].m$class()!==c$Module){m$raise(c$TypeError,$q(longName+' is not a Module'));};
|
84
|
+
newModule = namespace[c$name];
|
76
85
|
} else {
|
77
86
|
newModule = c$Module.m$new(longName);
|
78
|
-
namespace[
|
87
|
+
namespace[c$name] = newModule;
|
79
88
|
newModule.__includers__={};
|
80
89
|
};
|
81
90
|
if(typeof(block)=='function') { block.call(newModule); };
|
91
|
+
Red.updateIncluders(newModule);
|
82
92
|
},
|
83
93
|
|
84
94
|
_class: function(longName,superclass,block){
|
85
|
-
var newClass,context=Red.interpretNamespace(longName),namespace=context[0],name=context[1];
|
86
|
-
if(namespace[
|
87
|
-
if(name
|
88
|
-
|
95
|
+
var newClass,context=Red.interpretNamespace(longName),namespace=context[0],name=context[1],c$name='c$'+name;
|
96
|
+
if(namespace[c$name]) {
|
97
|
+
if(namespace[c$name].m$class&&namespace[c$name].m$class()!==c$Class){m$raise(c$TypeError,$q(longName+' is not a Class'));};
|
98
|
+
if(name!=='Object'&&superclass!==namespace[c$name].__superclass__){m$raise(c$TypeError,$q('superclass mismatch for class '+longName));};
|
99
|
+
newClass = namespace[c$name];
|
89
100
|
if(name=='Module'&&!(newClass.__superclass__.__children__[name])){Red.conferInheritance(c$Module,c$Object);}
|
90
101
|
if(name=='Class'&&!(newClass.__superclass__.__children__[name])){Red.conferInheritance(c$Class,c$Module);}
|
91
102
|
} else {
|
92
|
-
switch(name){
|
93
|
-
|
94
|
-
default: newClass = function() { this.__id__ = Red.id++ };
|
95
|
-
};
|
103
|
+
switch(name){case 'Array':newClass=Array;break;case 'Numeric':newClass=Number;break;default:newClass=function(){this.__id__=Red.id++;};};
|
104
|
+
if(superclass.m$class&&superclass.m$class()!==c$Class){m$raise(c$TypeError,$q('superclass must be a Class ('+superclass.m$class().__name__+' given)'))}
|
96
105
|
Red.conferInheritance(newClass,superclass);
|
97
106
|
Red.initializeClass(longName,newClass);
|
98
107
|
superclass.__children__[newClass.__name__]=true;
|
99
108
|
superclass.m$inherited && superclass.m$inherited(newClass);
|
100
|
-
namespace[
|
101
|
-
};
|
102
|
-
if(name == 'Object' || superclass == c$Object){
|
103
|
-
newClass.cvset = function(var_name,object) { return newClass['v$'+var_name] = object; };
|
104
|
-
newClass.cvget = function(var_name) { return newClass['v$'+var_name]; };
|
105
|
-
} else {
|
106
|
-
newClass.cvset = function() { return superclass.cvset.apply(null,arguments); };
|
107
|
-
newClass.cvget = function() { return superclass.cvget.apply(null,arguments); };
|
109
|
+
namespace[c$name]=newClass;
|
108
110
|
};
|
109
|
-
if(
|
111
|
+
if(name=='Object'||superclass==c$Object){newClass.cvset=function(v,o){return newClass['v$'+v]=o;};newClass.cvget=function(v){return newClass['v$'+v];};}else{newClass.cvset=function(v,o){return superclass.cvset(v,o);};newClass.cvget=function(v){return superclass.cvget(v);};};
|
112
|
+
if(typeof(block)=='function'){block.call(newClass);};
|
110
113
|
Red.updateChildren(newClass);
|
111
|
-
if((typeof(c$TrueClass)!='undefined'&&newClass==c$TrueClass)||(typeof(c$FalseClass)!='undefined'&&newClass==c$FalseClass))
|
114
|
+
if((typeof(c$TrueClass)!='undefined'&&newClass==c$TrueClass)||(typeof(c$FalseClass)!='undefined'&&newClass==c$FalseClass)){Red.donateMethodsToClass(newClass.prototype,Boolean.prototype,true);};
|
112
115
|
},
|
113
116
|
|
114
117
|
LoopError: {
|
115
|
-
_break:function(
|
116
|
-
_next:function(
|
118
|
+
_break:function(returnValue){var e=new(Error);e.__keyword__='break';e.__return__=returnValue==null?nil:returnValue;throw(e);},
|
119
|
+
_next:function(returnValue){var e=new(Error);e.__keyword__='next';e.__return__=returnValue==null?nil:returnValue;throw(e);},
|
117
120
|
_redo:function(){var e=new(Error);e.__keyword__='redo';throw(e);},
|
118
121
|
}
|
119
|
-
}
|
122
|
+
}
|
123
|
+
;
|
120
124
|
|
121
125
|
var $u=undefined,nil=null,$={};
|
122
126
|
|
@@ -125,18 +129,21 @@ c$Module = function(){this.__id__=Red.id++};c$Module.__name__='Module';c$Module.
|
|
125
129
|
c$Object = function(){this.__id__=Red.id++};c$Object.__name__='Object';c$Object.__children__={};c$Module.__superclass__=c$Object;
|
126
130
|
|
127
131
|
c$Object.prototype.toString=function(){return '#<'+this.m$class().__name__.replace(/\\./g,'::')+':0x'+(this.__id__*999^4000000).toString(16)+'>'};
|
128
|
-
Function.prototype.m$=function(o){var f=this;var p=function(){return f.apply(o,arguments);};p.
|
132
|
+
Function.prototype.m$=function(o){var f=this;var p=function(){return f.apply(o,arguments);};p.__unbound__=f;p.__arity__=f.arity;p.__id__=Red.id++;return p;};
|
129
133
|
window.__name__='window';
|
130
134
|
window.prototype=window;
|
131
135
|
window.__children__={'Object':true};
|
132
136
|
window.m$include=function(){for(var i=0,modules=arguments,l=modules.length;i<l;++i){var mp=modules[i].prototype;for(var x in mp){if(x.slice(0,2)=='m$'){var f=function(){return arguments.callee._source[arguments.callee._name].apply(window,arguments) };f._source=mp;f._name=x;window[x]=f;};};modules[i].m$included(window);modules[i].__includers__['window']=true;};if(modules[0]!=c$Kernel){Red.donateMethodsToClass(window,c$Object.prototype);Red.updateChildren(c$Object);};return window;};
|
133
|
-
window.m$
|
137
|
+
window.m$block_given_bool=function(){typeof(arguments[0])=='function'}
|
134
138
|
|
135
|
-
function $
|
136
|
-
function $
|
139
|
+
function $a(min,max,args,bg){var a=args.length-bg;if(a<min){n=min;}else{if(max!=-1&&a>max){n=max;}else{return;};};m$raise(c$ArgumentError, $q('wrong number of arguments ('+a+' for '+n+')'));}
|
140
|
+
function $e(e,ary){if(e.m$is_a_bool){for(var i=0,l=ary.length;i<l;++i){if(e.m$is_a_bool(ary[i])){return true;};};};return false;};
|
141
|
+
function $m(obj,name){var str=obj.m$inspect().__value__;str=str[0]=='#'?str:str+':'+obj.m$class().__name__;m$raise(c$NoMethodError, $q('undefined method "'+name+'" for '+str));}
|
142
|
+
function $n(obj,name){var str=obj.m$inspect().__value__;str=str[0]=='#'?str:str+':'+obj.m$class().__name__;m$raise(c$NameError, $q('undefined local variable or method "'+name+'" for '+str));}
|
143
|
+
function $Q(){for(var i=1,s=arguments[0],l=arguments.length;i<l;++i){s+=$q(arguments[i]).m$to_s().__value__;};return $q(s);};
|
137
144
|
function $q(obj){if(typeof obj!=='string'){return obj;};return c$String.m$new(obj);};
|
138
145
|
function $r(value,options){return c$Regexp.m$new(value,options);};
|
139
|
-
function $s(value){return(c$Symbol.
|
146
|
+
function $s(value){return(c$Symbol.__table__[value]||c$Symbol.m$new(value));};
|
140
147
|
function $T(x){return x!==false&&x!==nil&&x!=undefined;};
|
141
148
|
|
142
149
|
`
|
@@ -170,7 +177,7 @@ class Object
|
|
170
177
|
# may override this behavior.
|
171
178
|
#
|
172
179
|
def ==(other)
|
173
|
-
`this.__id__
|
180
|
+
`this.__id__===other.__id__`
|
174
181
|
end
|
175
182
|
|
176
183
|
# call-seq:
|
@@ -181,7 +188,7 @@ class Object
|
|
181
188
|
# semantics in case statements.
|
182
189
|
#
|
183
190
|
def ===(other)
|
184
|
-
`this.__id__
|
191
|
+
`this.__id__===other.__id__`
|
185
192
|
end
|
186
193
|
|
187
194
|
# call-seq:
|
@@ -224,8 +231,8 @@ class Object
|
|
224
231
|
# k.__send__(:hello, "gentle", "readers") #=> "Hello gentle readers"
|
225
232
|
#
|
226
233
|
def __send__(method,*args)
|
227
|
-
`method=this['m$'+sym.
|
228
|
-
`if(!method){m$raise(c$NoMethodError,$q('undefined method "'+sym.
|
234
|
+
`method=this['m$'+sym.__value__.replace('=','_eql').replace('!','_bang').replace('?','_bool')]`
|
235
|
+
`if(!method){m$raise(c$NoMethodError,$q('undefined method "'+sym.__value__+'" for '+this));}`
|
229
236
|
`method.apply(this,args)`
|
230
237
|
end
|
231
238
|
|
@@ -364,7 +371,7 @@ class Object
|
|
364
371
|
# k.hello #=> "Hello from Mod"
|
365
372
|
#
|
366
373
|
def extend(*modules)
|
367
|
-
`for(var i=0,l=modules.length;i<l;++i){modules[i].m$
|
374
|
+
`for(var i=0,l=modules.length;i<l;++i){modules[i].m$extend_object(this);modules[i].m$extended(this);}`
|
368
375
|
return self
|
369
376
|
end
|
370
377
|
|
@@ -387,7 +394,7 @@ class Object
|
|
387
394
|
# not overridden, uses the +to_s+ method to generate the string.
|
388
395
|
#
|
389
396
|
def inspect
|
390
|
-
`this.m$
|
397
|
+
`this.m$to_s()`
|
391
398
|
end
|
392
399
|
|
393
400
|
# call-seq:
|
@@ -407,7 +414,7 @@ class Object
|
|
407
414
|
# k.instance_eval { @secret } #=> 99
|
408
415
|
#
|
409
416
|
def instance_eval(&block)
|
410
|
-
`block.
|
417
|
+
`block.__block__.m$(this)()`
|
411
418
|
end
|
412
419
|
|
413
420
|
# call-seq:
|
@@ -436,7 +443,7 @@ class Object
|
|
436
443
|
# k.instance_variable_defined?("@b") #=> false
|
437
444
|
#
|
438
445
|
def instance_variable_defined?(name)
|
439
|
-
`this[name.
|
446
|
+
`this[name.__value__.replace('@','i$')]!=null`
|
440
447
|
end
|
441
448
|
|
442
449
|
# call-seq:
|
@@ -456,7 +463,7 @@ class Object
|
|
456
463
|
# k.instance_variable_get(:@a) #=> 99
|
457
464
|
#
|
458
465
|
def instance_variable_get(name)
|
459
|
-
`var v=this[name.
|
466
|
+
`var v=this[name.__value__.replace('@','i$')]`
|
460
467
|
`v==null?nil:v`
|
461
468
|
end
|
462
469
|
|
@@ -478,7 +485,7 @@ class Object
|
|
478
485
|
#
|
479
486
|
# FIX: Incomplete
|
480
487
|
def instance_variable_set(name, obj)
|
481
|
-
`this[name.
|
488
|
+
`this[name.__value__.replace('@','i$')]=obj`
|
482
489
|
end
|
483
490
|
|
484
491
|
# call-seq:
|
@@ -500,7 +507,7 @@ class Object
|
|
500
507
|
#
|
501
508
|
def instance_variables
|
502
509
|
`var result=[]`
|
503
|
-
`for(var x in this){if(x.slice(0,2)=='i$'){result.push($q('@'
|
510
|
+
`for(var x in this){if(x.slice(0,2)=='i$'){result.push($q('@'+x.slice(2,x.length)));};}`
|
504
511
|
return `result`
|
505
512
|
end
|
506
513
|
|
@@ -616,8 +623,8 @@ class Object
|
|
616
623
|
# k.methods.length #=> 42
|
617
624
|
#
|
618
625
|
def methods
|
619
|
-
`var result=[]`
|
620
|
-
`for(var x in this){if(x.slice(0,2)=='m$'&&x!='m$initialize'){
|
626
|
+
`var result=[],sub={_eql2:'==',_eql3:'===',_etld:'=~',_brac:'[]',_breq:'[]=',_lteq:'<=',_gteq:'>=',_ltlt:'<<',_gtgt:'>>',_lthn:'<',_gthn:'>',_ltgt:'<=>',_pipe:'|',_ampe:'&',_plus:'+',_posi:'+@',_nega:'-@',_star:'*',_str2:'**',_slsh:'/',_perc:'%',_care:'^',_tild:'~'}`
|
627
|
+
`for(var x in this){if(x.slice(0,2)=='m$'&&x!='m$initialize'){var str=x.slice(2,x.length);str=sub[str]||str;result.push($q(str.replace('_bool','?').replace('_bang','!').replace('_eql','=')));};}`
|
621
628
|
return `result`
|
622
629
|
end
|
623
630
|
|
@@ -671,7 +678,7 @@ class Object
|
|
671
678
|
# Returns +true+ if _obj_ responds to the given method.
|
672
679
|
#
|
673
680
|
def respond_to?(method)
|
674
|
-
`typeof(this['m$'+method.
|
681
|
+
`typeof(this['m$'+method.__value__])=='function'`
|
675
682
|
end
|
676
683
|
|
677
684
|
# call-seq:
|
@@ -692,8 +699,9 @@ class Object
|
|
692
699
|
# k.send(:hello, "gentle", "readers") #=> "Hello gentle readers"
|
693
700
|
#
|
694
701
|
def send(sym,*args)
|
695
|
-
`
|
696
|
-
`
|
702
|
+
`var str=sym.__value__.replace('=','_eql').replace('!','_bang').replace('?','_bool');sub={'==':'_eql2','===':'_eql3','=~':'_etld','[]':'_brac','[]=':'_breq','<=':'_lteq','>=':'_gteq','<<':'_ltlt','>>':'_gtgt','<':'_lthn','>':'_gthn','<=>':'_ltgt','|':'_pipe','&':'_ampe','+':'_plus','+@':'_posi','-@':'_nega','*':'_star','**':'_str2','/':'_slsh','%':'_perc','^':'_care','~':'_tild'}`
|
703
|
+
`var method=this['m$'+(sub[str]||str)]`
|
704
|
+
`if(!method){m$raise(c$NoMethodError,$q('undefined method "'+sym.__value__+'" for '+this));}`
|
697
705
|
`method.apply(this,args)`
|
698
706
|
end
|
699
707
|
|
@@ -778,7 +786,7 @@ class Module
|
|
778
786
|
# a.say_bye #=> "goodbye"
|
779
787
|
#
|
780
788
|
def initialize(module_name, &block)
|
781
|
-
`this.__name__=
|
789
|
+
`this.__name__=module_name.__value__||module_name`
|
782
790
|
`this.prototype={}`
|
783
791
|
end
|
784
792
|
|
@@ -792,7 +800,7 @@ class Module
|
|
792
800
|
end
|
793
801
|
|
794
802
|
def ===(obj)
|
795
|
-
`obj.m$
|
803
|
+
`obj.m$is_a_bool(this)`
|
796
804
|
end
|
797
805
|
|
798
806
|
def >(other_module)
|
@@ -820,28 +828,29 @@ class Module
|
|
820
828
|
def append_features(mod)
|
821
829
|
`Red.donateMethodsToSingleton(this,mod)`
|
822
830
|
`Red.donateMethodsToClass(this.prototype,mod.prototype)`
|
831
|
+
`Red.donateConstantsToClass(this,mod)`
|
823
832
|
return `mod`
|
824
833
|
end
|
825
834
|
|
826
835
|
def attr(attribute, writer = false)
|
827
|
-
`var a=attribute.
|
836
|
+
`var a=attribute.__value__`
|
828
837
|
`f1=this.prototype['m$'+a]=function(){return this['i$'+arguments.callee._name];};f1._name=a`
|
829
|
-
`if(writer){f2=this.prototype['m$'+a.
|
838
|
+
`if(writer){f2=this.prototype['m$'+a.__value__+'_eql']=function(x){return this['i$'+arguments.callee._name]=x;};f2._name=a;}`
|
830
839
|
return nil
|
831
840
|
end
|
832
841
|
|
833
842
|
def attr_accessor(*symbols)
|
834
843
|
`for(var i=0,l=symbols.length;i<l;++i){
|
835
|
-
var a=symbols[i].
|
844
|
+
var a=symbols[i].__value__;
|
836
845
|
f1=this.prototype['m$'+a]=function(){return this['i$'+arguments.callee._name];};f1._name=a;
|
837
|
-
f2=this.prototype['m$'+a+'
|
846
|
+
f2=this.prototype['m$'+a+'_eql']=function(x){return this['i$'+arguments.callee._name]=x;};f2._name=a;
|
838
847
|
}`
|
839
848
|
return nil
|
840
849
|
end
|
841
850
|
|
842
851
|
def attr_reader(*symbols)
|
843
852
|
`for(var i=0,l=symbols.length;i<l;++i){
|
844
|
-
var a=symbols[i].
|
853
|
+
var a=symbols[i].__value__;
|
845
854
|
f=this.prototype['m$'+a]=function(){return this['i$'+arguments.callee._name];};f._name=a;
|
846
855
|
}`
|
847
856
|
return nil
|
@@ -849,8 +858,8 @@ class Module
|
|
849
858
|
|
850
859
|
def attr_writer(*symbols)
|
851
860
|
`for(var i=0,l=symbols.length;i<l;++i){
|
852
|
-
var a=symbols[i].
|
853
|
-
f=this.prototype['m$'+a+'
|
861
|
+
var a=symbols[i].__value__;
|
862
|
+
f=this.prototype['m$'+a+'_eql']=function(x){return this['i$'+arguments.callee._name]=x;};f._name=a;
|
854
863
|
}`
|
855
864
|
return nil
|
856
865
|
end
|
@@ -975,7 +984,7 @@ class Module
|
|
975
984
|
# k.hello #=> "Hello from Mod"
|
976
985
|
#
|
977
986
|
def include(*modules)
|
978
|
-
`for(var i=0,l=modules.length;i<l;++i){var mod=modules[i];mod.m$
|
987
|
+
`for(var i=0,l=modules.length;i<l;++i){var mod=modules[i];mod.m$append_features(this);mod.m$included(this);mod.__includers__[this.__name__]=true;}`
|
979
988
|
return self
|
980
989
|
end
|
981
990
|
|
@@ -1077,8 +1086,8 @@ class Class < Module
|
|
1077
1086
|
#
|
1078
1087
|
# FIX: Incomplete
|
1079
1088
|
def self.new(class_name, superclass = Object)
|
1080
|
-
`Red._class(
|
1081
|
-
return `window['c$'+
|
1089
|
+
`Red._class(class_name.__value__,superclass,function(){})`
|
1090
|
+
return `window['c$'+class_name.__value__]`
|
1082
1091
|
end
|
1083
1092
|
|
1084
1093
|
# call-seq:
|
@@ -1294,8 +1303,8 @@ end
|
|
1294
1303
|
#
|
1295
1304
|
module Kernel
|
1296
1305
|
# FIX: Incomplete
|
1297
|
-
def block_given?
|
1298
|
-
`typeof(
|
1306
|
+
def block_given?(x)
|
1307
|
+
`typeof(x)=='function'`
|
1299
1308
|
end
|
1300
1309
|
|
1301
1310
|
# FIX: Incomplete
|
@@ -1318,8 +1327,9 @@ module Kernel
|
|
1318
1327
|
#
|
1319
1328
|
# FIX: Incomplete
|
1320
1329
|
def lambda(func)
|
1321
|
-
`result=new(c$Proc)()`
|
1322
|
-
`result.
|
1330
|
+
`var result=new(c$Proc)()`
|
1331
|
+
`result.__block__=func`
|
1332
|
+
`result.__block__.__id__=Red.id++`
|
1323
1333
|
return `result`
|
1324
1334
|
end
|
1325
1335
|
|
@@ -1358,8 +1368,9 @@ module Kernel
|
|
1358
1368
|
#
|
1359
1369
|
# FIX: Incomplete
|
1360
1370
|
def proc(func)
|
1361
|
-
`result=new(c$Proc)()`
|
1362
|
-
`result.
|
1371
|
+
`var result=new(c$Proc)()`
|
1372
|
+
`result.__block__=func`
|
1373
|
+
`result.__block__.__id__=Red.id++`
|
1363
1374
|
return `result`
|
1364
1375
|
end
|
1365
1376
|
|
@@ -1375,15 +1386,15 @@ module Kernel
|
|
1375
1386
|
#
|
1376
1387
|
# FIX: Incomplete
|
1377
1388
|
def puts(obj)
|
1378
|
-
`var string=obj.m$
|
1379
|
-
`console.log(string.
|
1389
|
+
`var string=obj.m$to_s&&obj.m$to_s()||$q(''+obj)`
|
1390
|
+
`console.log(string.__value__.replace(/\\\\/g,'\\\\\\\\'))`
|
1380
1391
|
return nil
|
1381
1392
|
end
|
1382
1393
|
|
1383
1394
|
# FIX: Incomplete
|
1384
|
-
def raise
|
1395
|
+
def raise(*args)
|
1385
1396
|
`var exception_class=c$RuntimeError,msg=$q('')`
|
1386
|
-
`if(arguments[0]&&arguments[0].m$
|
1397
|
+
`if(arguments[0]&&arguments[0].m$is_a_bool(c$Exception)){
|
1387
1398
|
var e=arguments[0];
|
1388
1399
|
}else{
|
1389
1400
|
if(arguments[0]&&arguments[0].m$class()==c$String){
|
@@ -1395,7 +1406,7 @@ module Kernel
|
|
1395
1406
|
}
|
1396
1407
|
}`
|
1397
1408
|
`var e=e||exception_class.m$new(msg)`
|
1398
|
-
`e.
|
1409
|
+
`e.__stack__=new Error().stack`
|
1399
1410
|
`throw(e)`
|
1400
1411
|
return nil
|
1401
1412
|
end
|
@@ -1437,13 +1448,13 @@ module Kernel
|
|
1437
1448
|
|
1438
1449
|
# FIX: Incomplete
|
1439
1450
|
def sprintf(string)
|
1440
|
-
`var i=1,source=string.
|
1451
|
+
`var i=1,source=string.__value__,result=[],m=$u,arg=$u,val=$u,str=$u,dL=$u,chr=$u,pad=$u;
|
1441
1452
|
while(source){
|
1442
1453
|
if(m=source.match(/^[^%]+/)){result.push(m[0]);source=source.slice(m[0].length);continue;};
|
1443
1454
|
if(m=source.match(/^%%/)) {result.push('%'); source=source.slice(m[0].length);continue;};
|
1444
1455
|
// 1(0)2(wdth) 3(prec) 4(field-type )
|
1445
1456
|
if(m=source.match(/^%(0)?(\\d+)?(?:\\.(\\d+))?([bcdEefGgiopsuXx])/)){
|
1446
|
-
arg = arguments[i].
|
1457
|
+
arg = arguments[i].__value__||arguments[i];
|
1447
1458
|
switch(m[4]){
|
1448
1459
|
case'b':str=parseFloat(arg).toString(2);break;
|
1449
1460
|
case'c':str=String.fromCharCode(arg);break;
|
@@ -1455,8 +1466,8 @@ module Kernel
|
|
1455
1466
|
case'g':str='-FIX-';break;
|
1456
1467
|
case'i':val=parseInt(arg);str=''+val;break;
|
1457
1468
|
case'o':str=parseFloat(arg).toString(8);break;
|
1458
|
-
case'p':str=$q(arg).m$inspect().
|
1459
|
-
case's':val=arg.m$
|
1469
|
+
case'p':str=$q(arg).m$inspect().__value__;break;
|
1470
|
+
case's':val=arg.m$to_s&&arg.m$to_s().__value__||arg;str=(m[3]?val.slice(0,m[2]):val);break;
|
1460
1471
|
case'u':val=parseInt(arg);str=''+(val<0?'..'+(Math.pow(2,32)+val):val);break;
|
1461
1472
|
case'X':str=parseInt(arg).toString(16).toUpperCase();break;
|
1462
1473
|
case'x':str=parseInt(arg).toString(16);break;
|
@@ -1758,7 +1769,7 @@ class Array
|
|
1758
1769
|
# [1,2,3] * 3 #=> [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
1759
1770
|
#
|
1760
1771
|
def *(arg)
|
1761
|
-
`if(arg.m$class()==c$String){return this.join(arg);}`
|
1772
|
+
`if(arg.m$class()==c$String){return $q(this.join(arg));}`
|
1762
1773
|
`var result=[],i=0,l=parseInt(arg)`
|
1763
1774
|
`while(i<l){result=result.concat(this);i++;}`
|
1764
1775
|
return `result`
|
@@ -1866,10 +1877,10 @@ class Array
|
|
1866
1877
|
# a[5,1] #=> []
|
1867
1878
|
# a[5..10] #=> []
|
1868
1879
|
#
|
1869
|
-
def [](index, length)
|
1880
|
+
def [](index, length = nil)
|
1870
1881
|
`var l=this.length`
|
1871
1882
|
`if(index.m$class()==c$Range){
|
1872
|
-
var start=index.
|
1883
|
+
var start=index.__start__,end=index.__exclusive__?index.__end__-1:index.__end__;
|
1873
1884
|
index=start<0?start+l:start;
|
1874
1885
|
length=(end<0?end+l:end)-index+1;
|
1875
1886
|
if(length<0){length=0};
|
@@ -1910,13 +1921,17 @@ class Array
|
|
1910
1921
|
def []=(index, length, object)
|
1911
1922
|
`var l=this.length`
|
1912
1923
|
`if(object==null){object=length;length=$u;}`
|
1913
|
-
`if(index.m$class()==c$Range){var start=index.
|
1924
|
+
`if(index.m$class()==c$Range){var start=index.__start__,end=index.__exclusive__?index.__end__-1:index.__end__;index=start<0?start+l:start;length=(end<0?end+l:end)-index+1;if(length<0){length=0};}else{if(index<0){index+=l;};if(length<0){throw('IndexError: negative length')}}`
|
1914
1925
|
`if(index<0){throw('RangeError: out of range');}`
|
1915
1926
|
`while(this.length<index){this.push(nil);}`
|
1916
1927
|
`if($T(length)){var l=this.length,final=(index+length>l)?l:index+length;this._replace(this.slice(0,index).concat(object===nil?[]:(object.m$class()==c$Array?object:[object])).concat(this.slice(final,l)))}else{this[index]=object}`
|
1917
1928
|
return `object`
|
1918
1929
|
end
|
1919
1930
|
|
1931
|
+
def __id__ # :nodoc:
|
1932
|
+
`this.__id__||(this.__id__=Red.id++)`
|
1933
|
+
end
|
1934
|
+
|
1920
1935
|
# call-seq:
|
1921
1936
|
# ary.assoc(obj) -> array or nil
|
1922
1937
|
#
|
@@ -1981,7 +1996,7 @@ class Array
|
|
1981
1996
|
# a #=> [1, 2, 3, 4]
|
1982
1997
|
#
|
1983
1998
|
def collect
|
1984
|
-
`for(var i=0,l=this.length,result=[];i<l;++i){try{result[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':result[i]=e.
|
1999
|
+
`for(var i=0,l=this.length,result=[];i<l;++i){try{result[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':result[i]=e.__return__;break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
1985
2000
|
return `result`
|
1986
2001
|
end
|
1987
2002
|
|
@@ -1999,7 +2014,7 @@ class Array
|
|
1999
2014
|
# a.collect! {|x| x + 100 } #=> [201, 202, 203, 204]
|
2000
2015
|
#
|
2001
2016
|
def collect!
|
2002
|
-
`for(var i=0,l=this.length;i<l;++i){try{this[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':this[i]=e.
|
2017
|
+
`for(var i=0,l=this.length;i<l;++i){try{this[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':this[i]=e.__return__;break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2003
2018
|
return self
|
2004
2019
|
end
|
2005
2020
|
|
@@ -2062,7 +2077,7 @@ class Array
|
|
2062
2077
|
def delete(obj)
|
2063
2078
|
`for(var i=0,l=this.length,temp=[];i<l;++i){if(!(this[i].m$_eql2(obj))){temp.push(this[i]);};}`
|
2064
2079
|
`this._replace(temp)`
|
2065
|
-
return `l===this.length?(
|
2080
|
+
return `l===this.length?(#{block_given?}?#{yield}:nil):obj`
|
2066
2081
|
end
|
2067
2082
|
|
2068
2083
|
# call-seq:
|
@@ -2098,7 +2113,7 @@ class Array
|
|
2098
2113
|
# a.delete_if {|element| element >= 'b' } #=> ["a"]
|
2099
2114
|
#
|
2100
2115
|
def delete_if
|
2101
|
-
`for(var temp=[],i=0,l=this.length;i<l;++i){try{if(!$T(#{yield `this[i]`})){temp.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.
|
2116
|
+
`for(var temp=[],i=0,l=this.length;i<l;++i){try{if(!$T(#{yield `this[i]`})){temp.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.__return__)){temp.push(this[i]);};break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2102
2117
|
`this._replace(temp)`
|
2103
2118
|
end
|
2104
2119
|
|
@@ -2116,7 +2131,7 @@ class Array
|
|
2116
2131
|
# C
|
2117
2132
|
#
|
2118
2133
|
def each
|
2119
|
-
`for(var i=0,l=this.length;i<l;++i){try{#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
2134
|
+
`for(var i=0,l=this.length;i<l;++i){try{#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2120
2135
|
return self
|
2121
2136
|
end
|
2122
2137
|
|
@@ -2134,7 +2149,7 @@ class Array
|
|
2134
2149
|
# 102
|
2135
2150
|
#
|
2136
2151
|
def each_index
|
2137
|
-
`for(var i=0,l=this.length;i<l;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
2152
|
+
`for(var i=0,l=this.length;i<l;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2138
2153
|
return self
|
2139
2154
|
end
|
2140
2155
|
|
@@ -2163,10 +2178,15 @@ class Array
|
|
2163
2178
|
#
|
2164
2179
|
def eql?(ary)
|
2165
2180
|
`if(ary.m$class()!==c$Array||ary.length!==this.length){return false;}`
|
2166
|
-
`for(var i=0,l=this.length;i<l;++i){if(!(this[i].m$
|
2181
|
+
`for(var i=0,l=this.length;i<l;++i){if(!(this[i].m$eql_bool(ary[i]))){return false;};}`
|
2167
2182
|
return true
|
2168
2183
|
end
|
2169
2184
|
|
2185
|
+
def equal?(ary) # :nodoc:
|
2186
|
+
`var thisId=this.__id__||(this.__id__=Red.id++),aryId=ary.__id__||(ary.__id__=Red.id++)`
|
2187
|
+
`thisId==aryId`
|
2188
|
+
end
|
2189
|
+
|
2170
2190
|
# call-seq:
|
2171
2191
|
# ary.fetch(index) -> object or nil
|
2172
2192
|
# ary.fetch(index, default) -> object or default
|
@@ -2272,8 +2292,9 @@ class Array
|
|
2272
2292
|
# a.flatten! #=> nil
|
2273
2293
|
#
|
2274
2294
|
def flatten!
|
2275
|
-
`for(var i=0,l=
|
2276
|
-
|
2295
|
+
`var flatten=function(ary){for(var i=0,l=ary.length,result=[];i<l;++i){if(ary[i].m$class()==c$Array){result=result.concat(ary[i].m$flatten());}else{result.push(ary[i]);};};return result;}`
|
2296
|
+
`for(var i=0,l=this.length,result=[];i<l;++i){if(this[i].m$class()==c$Array){result=result.concat(flatten(this[i]));}else{result.push(this[i]);};}`
|
2297
|
+
return `l==result.length?nil:this._replace(result)`
|
2277
2298
|
end
|
2278
2299
|
|
2279
2300
|
def hash # :nodoc:
|
@@ -2336,7 +2357,7 @@ class Array
|
|
2336
2357
|
# [1,2,3].inspect #=> "[1, 2, 3]"
|
2337
2358
|
#
|
2338
2359
|
def inspect
|
2339
|
-
`for(var i=1,l=this.length,result='['+(this[0]!=null?this[0].m$inspect().
|
2360
|
+
`for(var i=1,l=this.length,result='['+(this[0]!=null?this[0].m$inspect().__value__:'');i<l;++i){result+=', '+this[i].m$inspect().__value__;}`
|
2340
2361
|
return `$q(result+']')`
|
2341
2362
|
end
|
2342
2363
|
|
@@ -2351,8 +2372,8 @@ class Array
|
|
2351
2372
|
# %w(a b c).join('.') #=> "a.b.c"
|
2352
2373
|
#
|
2353
2374
|
def join(str = '')
|
2354
|
-
`var result=this[0]!=null?this[0].m$join?this[0].m$join(str.
|
2355
|
-
`for(var i=1,l=this.length;i<l;++i){result+=(str.
|
2375
|
+
`var result=this[0]!=null?this[0].m$join?this[0].m$join(str.__value__).__value__:this[0].m$to_s().__value__:''`
|
2376
|
+
`for(var i=1,l=this.length;i<l;++i){result+=(str.__value__||'')+(this[i].m$join?this[i].m$join(str).__value__:this[i].m$to_s().__value__);}`
|
2356
2377
|
return `$q(result)`
|
2357
2378
|
end
|
2358
2379
|
|
@@ -2402,7 +2423,7 @@ class Array
|
|
2402
2423
|
# a #=> [1, 2, 3, 4]
|
2403
2424
|
#
|
2404
2425
|
def map
|
2405
|
-
`for(var i=0,l=this.length,result=[];i<l;++i){try{result[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':result[i]=e.
|
2426
|
+
`for(var i=0,l=this.length,result=[];i<l;++i){try{result[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':result[i]=e.__return__;break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2406
2427
|
return `result`
|
2407
2428
|
end
|
2408
2429
|
|
@@ -2420,7 +2441,7 @@ class Array
|
|
2420
2441
|
# a.map! {|x| x + 100 } #=> [201, 202, 203, 204]
|
2421
2442
|
#
|
2422
2443
|
def map!
|
2423
|
-
`for(var i=0,l=this.length;i<l;++i){try{this[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':this[i]=e.
|
2444
|
+
`for(var i=0,l=this.length;i<l;++i){try{this[i]=#{yield `this[i]`};}catch(e){switch(e.__keyword__){case 'next':this[i]=e.__return__;break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2424
2445
|
return self
|
2425
2446
|
end
|
2426
2447
|
|
@@ -2436,6 +2457,10 @@ class Array
|
|
2436
2457
|
return `result`
|
2437
2458
|
end
|
2438
2459
|
|
2460
|
+
def object_id # :nodoc:
|
2461
|
+
`this.__id__||(this.__id__=Red.id++)`
|
2462
|
+
end
|
2463
|
+
|
2439
2464
|
# call-seq:
|
2440
2465
|
# ary.pop -> object or nil
|
2441
2466
|
#
|
@@ -2498,7 +2523,7 @@ class Array
|
|
2498
2523
|
# a #=> [1, 2, 3, 4, 5]
|
2499
2524
|
#
|
2500
2525
|
def reject
|
2501
|
-
`for(var i=0,l=this.length,result=[];i<l;++i){try{if(!$T(#{yield `this[i]`})){result.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.
|
2526
|
+
`for(var i=0,l=this.length,result=[];i<l;++i){try{if(!$T(#{yield `this[i]`})){result.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.__return__)){result.push(this[i]);};break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2502
2527
|
return `result`
|
2503
2528
|
end
|
2504
2529
|
|
@@ -2515,7 +2540,7 @@ class Array
|
|
2515
2540
|
# a #=> [1, 2, 3]
|
2516
2541
|
#
|
2517
2542
|
def reject!
|
2518
|
-
`for(var i=0,l=this.length,temp=[];i<l;++i){try{if(!$T(#{yield `this[i]`})){temp.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.
|
2543
|
+
`for(var i=0,l=this.length,temp=[];i<l;++i){try{if(!$T(#{yield `this[i]`})){temp.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.__return__)){temp.push(this[i]);};break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2519
2544
|
return `temp.length==l?nil:this._replace(temp)`
|
2520
2545
|
end
|
2521
2546
|
|
@@ -2545,7 +2570,8 @@ class Array
|
|
2545
2570
|
# a #=> [1, 2, 3, 4, 5]
|
2546
2571
|
#
|
2547
2572
|
def reverse
|
2548
|
-
`this.
|
2573
|
+
`for(var i=this.length,result=[];i>0;){result.push(this[--i]);}`
|
2574
|
+
return `result`
|
2549
2575
|
end
|
2550
2576
|
|
2551
2577
|
# call-seq:
|
@@ -2559,8 +2585,7 @@ class Array
|
|
2559
2585
|
# a #=> [5, 4, 3, 2, 1]
|
2560
2586
|
#
|
2561
2587
|
def reverse!
|
2562
|
-
`
|
2563
|
-
return self
|
2588
|
+
`this.reverse()`
|
2564
2589
|
end
|
2565
2590
|
|
2566
2591
|
# call-seq:
|
@@ -2578,7 +2603,7 @@ class Array
|
|
2578
2603
|
# A
|
2579
2604
|
#
|
2580
2605
|
def reverse_each
|
2581
|
-
`for(var i=this.length;i>0;){try{#{yield `this[--i]`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
2606
|
+
`for(var i=this.length;i>0;){try{#{yield `this[--i]`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':++i;break;default:throw(e);};};}`
|
2582
2607
|
return self
|
2583
2608
|
end
|
2584
2609
|
|
@@ -2607,7 +2632,7 @@ class Array
|
|
2607
2632
|
# [1,2,3,4,5].select {|x| x > 3 } #=> [4, 5]
|
2608
2633
|
#
|
2609
2634
|
def select
|
2610
|
-
`for(var i=0,l=this.length,result=[];i<l;++i){try{if($T(#{yield `this[i]`})){result.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.
|
2635
|
+
`for(var i=0,l=this.length,result=[];i<l;++i){try{if($T(#{yield `this[i]`})){result.push(this[i]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.__return__)){result.push(this[i]);};break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
2611
2636
|
return `result`
|
2612
2637
|
end
|
2613
2638
|
|
@@ -2690,7 +2715,7 @@ class Array
|
|
2690
2715
|
#
|
2691
2716
|
def slice!(index, length)
|
2692
2717
|
`var l=this.length`
|
2693
|
-
`if(index.m$class()==c$Range){var start=index.
|
2718
|
+
`if(index.m$class()==c$Range){var start=index.__start__,end=index.__exclusive__?index.__end__-1:index.__end__;index=start<0?start+l:start;length=(end<0?end+l:end)-index+1;if(length<0){length=0};}else{if(index<0){index+=l;};if(length<0){throw('IndexError: negative length')};}`
|
2694
2719
|
`if(index>=l){return nil;}`
|
2695
2720
|
`if(index<0){throw('RangeError: out of range');}`
|
2696
2721
|
`if($T(length)){if(length<=0){return [];};result=this.slice(index,index+length);this._replace(this.slice(0,index).concat(this.slice(index+length)));}else{result=this[index];this._replace(this.slice(0,index).concat(this.slice(index+1,l)));}`
|
@@ -2713,7 +2738,7 @@ class Array
|
|
2713
2738
|
#
|
2714
2739
|
# FIX: Doesn't handle loop control keywords
|
2715
2740
|
def sort(block)
|
2716
|
-
`c$Array.apply(null,this).
|
2741
|
+
`c$Array.apply(null,this)._quick_sort(0,this.length,block)`
|
2717
2742
|
end
|
2718
2743
|
|
2719
2744
|
# call-seq:
|
@@ -2732,7 +2757,7 @@ class Array
|
|
2732
2757
|
#
|
2733
2758
|
# FIX: Doesn't handle loop control keywords
|
2734
2759
|
def sort!(block)
|
2735
|
-
`this.
|
2760
|
+
`this._quick_sort(0,this.length,block)`
|
2736
2761
|
end
|
2737
2762
|
|
2738
2763
|
# call-seq:
|
@@ -2841,7 +2866,7 @@ class Array
|
|
2841
2866
|
end
|
2842
2867
|
|
2843
2868
|
`_._partition=function(first,last,pivot,block){var value=this[pivot],store=first;this._swap(pivot,last);for(var i=0,l=this.length;i<l;++i){if(i<first||i>=last){continue;};var cmp=block?block(this[i],value):this[i].m$_ltgt(value);if(cmp==-1||cmp==0){this._swap(store++,i);};};this._swap(last,store);return(store);}`
|
2844
|
-
`_.
|
2869
|
+
`_._quick_sort=function(start,finish,block){if(finish-1>start){var pivot=start+Math.floor(Math.random()*(finish-start));pivot=this._partition(start,(finish-1),pivot,block);this._quick_sort(start,pivot,block);this._quick_sort((pivot+1),finish,block);};return(this);}`
|
2845
2870
|
`_._replace=function(ary){this.length=0;for(var i=0,l=ary.length;i<l;++i){this.push(ary[i])};return this;}`
|
2846
2871
|
`_._swap=function(x,y){var z=this[x];this[x]=this[y];this[y]=z;return this;}`
|
2847
2872
|
end
|
@@ -2869,7 +2894,7 @@ class Exception
|
|
2869
2894
|
# Returns a new +Exception+ object, with an optional _message_.
|
2870
2895
|
#
|
2871
2896
|
def initialize(msg)
|
2872
|
-
`if(msg!=null){this.
|
2897
|
+
`if(msg!=null){this.__message__=msg.__value__;}`
|
2873
2898
|
end
|
2874
2899
|
|
2875
2900
|
# call-seq:
|
@@ -2879,8 +2904,8 @@ class Exception
|
|
2879
2904
|
# array of strings, each containing <i>"/path/to/filename:line"</i>.
|
2880
2905
|
#
|
2881
2906
|
def backtrace
|
2882
|
-
`if(this.
|
2883
|
-
`for(var i=0,lines=this.
|
2907
|
+
`if(this.__stack__==null){return [];}`
|
2908
|
+
`for(var i=0,lines=this.__stack__.match(/@[^\\n]+:\\d+/g),l=lines.length,result=[];i<l;++i){result.push($q(lines[i].match(/@\\w+:\\/*(\\/[^\\n]+:\\d+)/)[1]));}`
|
2884
2909
|
return `result`
|
2885
2910
|
end
|
2886
2911
|
|
@@ -2893,7 +2918,7 @@ class Exception
|
|
2893
2918
|
#
|
2894
2919
|
def exception(arg)
|
2895
2920
|
`if(arg==null||arg==this){return this;}`
|
2896
|
-
`this.m$class().m$new(arg.m$
|
2921
|
+
`this.m$class().m$new(arg.m$to_str())`
|
2897
2922
|
end
|
2898
2923
|
|
2899
2924
|
# call-seq:
|
@@ -2903,7 +2928,7 @@ class Exception
|
|
2903
2928
|
#
|
2904
2929
|
def inspect
|
2905
2930
|
`var class_name=this.m$class().__name__.replace(/\\./g,'::')`
|
2906
|
-
`this.
|
2931
|
+
`this.__message__==''?$q(class_name):$q('#<'+class_name+': '+(this.__message__||class_name)+'>')`
|
2907
2932
|
end
|
2908
2933
|
|
2909
2934
|
# call-seq:
|
@@ -2915,7 +2940,7 @@ class Exception
|
|
2915
2940
|
# is set).
|
2916
2941
|
#
|
2917
2942
|
def message
|
2918
|
-
`this.
|
2943
|
+
`this.__message__==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this.__message__)`
|
2919
2944
|
end
|
2920
2945
|
|
2921
2946
|
# call-seq:
|
@@ -2925,8 +2950,8 @@ class Exception
|
|
2925
2950
|
# an array of +String+ objects in the format described in
|
2926
2951
|
# <tt>Exception#backtrace</tt>.
|
2927
2952
|
def set_backtrace(ary)
|
2928
|
-
`for(var i=0,l=ary.length,result='';i<l;++i){result=result+'@xx://'+ary[i].
|
2929
|
-
`this.
|
2953
|
+
`for(var i=0,l=ary.length,result='';i<l;++i){result=result+'@xx://'+ary[i].__value__+'\\n';}`
|
2954
|
+
`this.__stack__=result`
|
2930
2955
|
return `ary`
|
2931
2956
|
end
|
2932
2957
|
|
@@ -2939,7 +2964,7 @@ class Exception
|
|
2939
2964
|
# is set).
|
2940
2965
|
#
|
2941
2966
|
def to_s
|
2942
|
-
`this.
|
2967
|
+
`this.__message__==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this.__message__)`
|
2943
2968
|
end
|
2944
2969
|
|
2945
2970
|
# call-seq:
|
@@ -2951,11 +2976,11 @@ class Exception
|
|
2951
2976
|
# is set).
|
2952
2977
|
#
|
2953
2978
|
def to_str
|
2954
|
-
`this.
|
2979
|
+
`this.__message__==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this.__message__)`
|
2955
2980
|
end
|
2956
2981
|
end
|
2957
2982
|
`
|
2958
|
-
c$Exception.prototype.toString=function(){var class_name=this.m$class().__name__.replace(/\\./g,'::'),str=class_name+': '+(this.
|
2983
|
+
c$Exception.prototype.toString=function(){var class_name=this.m$class().__name__.replace(/\\./g,'::'),str=class_name+': '+(this.__message__||class_name);console.log(str+(this.__stack__!=null?'\\n from '+this.m$backtrace().join('\\n from '):''));return '#<'+str+'>';}
|
2959
2984
|
`
|
2960
2985
|
class StandardError < Exception ; end
|
2961
2986
|
class ArgumentError < StandardError ; end
|
@@ -3046,7 +3071,7 @@ class Hash
|
|
3046
3071
|
#
|
3047
3072
|
def self.[](*args)
|
3048
3073
|
`if(args.length==1&&args[0].m$class()==c$Hash){return args[0];}`
|
3049
|
-
`for(var i=0,l=args.length,result=c$Hash.m$new(),c=result.
|
3074
|
+
`for(var i=0,l=args.length,result=c$Hash.m$new(),c=result.__contents__;i<l;i+=2){var k=args[i],v=args[i+1],h=k.m$hash();c[h]=[k,v]}`
|
3050
3075
|
return `result`
|
3051
3076
|
end
|
3052
3077
|
|
@@ -3084,9 +3109,9 @@ class Hash
|
|
3084
3109
|
# # Values from defaults are stored in the hash
|
3085
3110
|
# h2.keys #=> [:c, :d]
|
3086
3111
|
#
|
3087
|
-
def initialize(
|
3088
|
-
`this.
|
3089
|
-
`this.
|
3112
|
+
def initialize(*args,&block)
|
3113
|
+
`this.__default__=(args[0]==null?block==null?nil:block:args[0])`
|
3114
|
+
`this.__contents__={}`
|
3090
3115
|
end
|
3091
3116
|
|
3092
3117
|
# call-seq:
|
@@ -3105,7 +3130,7 @@ class Hash
|
|
3105
3130
|
# h3 == h4 #=> false
|
3106
3131
|
#
|
3107
3132
|
def ==(other)
|
3108
|
-
`var c=this.
|
3133
|
+
`var c=this.__contents__,o=other.__contents__`
|
3109
3134
|
`for(var x in o){if(x.slice(1,2)=='_'&&c[x]==null){return false;};}`
|
3110
3135
|
`for(var x in c){if(x.slice(1,2)=='_'&&!c[x][1].m$_eql2(o[x][1])){return false;};}`
|
3111
3136
|
return true
|
@@ -3124,8 +3149,8 @@ class Hash
|
|
3124
3149
|
# h[:c] => nil
|
3125
3150
|
#
|
3126
3151
|
def [](k)
|
3127
|
-
`var kv=this.
|
3128
|
-
`if(!kv){var d=this.
|
3152
|
+
`var kv=this.__contents__[k.m$hash()]`
|
3153
|
+
`if(!kv){var d=this.__default__;return(typeof(d)=='function'?d(this,kv[0]):d);}`
|
3129
3154
|
return `kv[1]`
|
3130
3155
|
end
|
3131
3156
|
|
@@ -3144,7 +3169,7 @@ class Hash
|
|
3144
3169
|
# h #=> {:a => 150, :b => 200, :c => 300}
|
3145
3170
|
#
|
3146
3171
|
def []=(k,v)
|
3147
|
-
`this.
|
3172
|
+
`this.__contents__[k.m$hash()]=[k,v]`
|
3148
3173
|
return `v`
|
3149
3174
|
end
|
3150
3175
|
|
@@ -3159,7 +3184,7 @@ class Hash
|
|
3159
3184
|
# h #=> {}
|
3160
3185
|
#
|
3161
3186
|
def clear
|
3162
|
-
`this.
|
3187
|
+
`this.__contents__={}`
|
3163
3188
|
return self
|
3164
3189
|
end
|
3165
3190
|
|
@@ -3183,7 +3208,7 @@ class Hash
|
|
3183
3208
|
# h.default(2) #=> 20
|
3184
3209
|
#
|
3185
3210
|
def default(key = nil)
|
3186
|
-
`var d=this.
|
3211
|
+
`var d=this.__default__`
|
3187
3212
|
return `typeof(d)=='function'?d(this,key):d`
|
3188
3213
|
end
|
3189
3214
|
|
@@ -3207,7 +3232,7 @@ class Hash
|
|
3207
3232
|
# h['foo'] #=> #<Proc:201>
|
3208
3233
|
#
|
3209
3234
|
def default=(obj)
|
3210
|
-
`this.
|
3235
|
+
`this.__default__=obj`
|
3211
3236
|
return self
|
3212
3237
|
end
|
3213
3238
|
|
@@ -3224,7 +3249,7 @@ class Hash
|
|
3224
3249
|
# a #=> [nil, nil, 4]
|
3225
3250
|
#
|
3226
3251
|
def default_proc
|
3227
|
-
`var d=this.
|
3252
|
+
`var d=this.__default__`
|
3228
3253
|
return `typeof(d)=='function'?c$Proc.m$new(d):nil`
|
3229
3254
|
end
|
3230
3255
|
|
@@ -3244,7 +3269,7 @@ class Hash
|
|
3244
3269
|
# h.delete(:z) {|k| "#{k.inspect} not found" } #=> ":z not found"
|
3245
3270
|
#
|
3246
3271
|
def delete(k)
|
3247
|
-
`var c=this.
|
3272
|
+
`var c=this.__contents__,d=this.__default__,x=k.m$hash(),kv=c[x]`
|
3248
3273
|
`if(kv!=null){var result=kv[1];delete(c[x]);return result;}`
|
3249
3274
|
return `typeof(_block)=='function'?#{yield `k`}:(typeof(d)=='function'?d(this,k):d)`
|
3250
3275
|
end
|
@@ -3260,8 +3285,8 @@ class Hash
|
|
3260
3285
|
# h.delete_if {|k,v| v >= 200 } #=> {:a => 100}
|
3261
3286
|
#
|
3262
3287
|
def delete_if
|
3263
|
-
`var c=this.
|
3264
|
-
`for(var x in c){try{if(x.slice(1,2)=='_'&&$T(#{yield(`c[x][0]`,`c[x][1]`)})){delete(c[x]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.
|
3288
|
+
`var c=this.__contents__`
|
3289
|
+
`for(var x in c){try{if(x.slice(1,2)=='_'&&$T(#{yield(`c[x][0]`,`c[x][1]`)})){delete(c[x]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.__return__)){delete(c[x]);};break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3265
3290
|
return self
|
3266
3291
|
end
|
3267
3292
|
|
@@ -3287,8 +3312,8 @@ class Hash
|
|
3287
3312
|
# key-value array is [:b, 100]
|
3288
3313
|
#
|
3289
3314
|
def each
|
3290
|
-
`var c=this.
|
3291
|
-
`for(var x in c){try{if(x.slice(1,2)=='_'){var kv=c[x];_block.
|
3315
|
+
`var c=this.__contents__`
|
3316
|
+
`for(var x in c){try{if(x.slice(1,2)=='_'){var kv=c[x];_block.__arity__==1?#{yield(`[kv[0],kv[1]]`)}:#{yield(`kv[0],kv[1]`)}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3292
3317
|
return self
|
3293
3318
|
end
|
3294
3319
|
|
@@ -3307,8 +3332,8 @@ class Hash
|
|
3307
3332
|
# :b
|
3308
3333
|
#
|
3309
3334
|
def each_key
|
3310
|
-
`var c=this.
|
3311
|
-
`for(var x in c){try{if(x.slice(1,2)=='_'){#{yield `c[x][0]`}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.
|
3335
|
+
`var c=this.__contents__`
|
3336
|
+
`for(var x in c){try{if(x.slice(1,2)=='_'){#{yield `c[x][0]`}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3312
3337
|
return self
|
3313
3338
|
end
|
3314
3339
|
|
@@ -3328,8 +3353,8 @@ class Hash
|
|
3328
3353
|
# :b is 200
|
3329
3354
|
#
|
3330
3355
|
def each_pair
|
3331
|
-
`var c=this.
|
3332
|
-
`for(var x in c){try{if(x.slice(1,2)=='_'){var kv=c[x];#{yield(`kv[0]`,`kv[1]`)}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.
|
3356
|
+
`var c=this.__contents__`
|
3357
|
+
`for(var x in c){try{if(x.slice(1,2)=='_'){var kv=c[x];#{yield(`kv[0]`,`kv[1]`)}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3333
3358
|
return self
|
3334
3359
|
end
|
3335
3360
|
|
@@ -3349,8 +3374,8 @@ class Hash
|
|
3349
3374
|
# 200
|
3350
3375
|
#
|
3351
3376
|
def each_value
|
3352
|
-
`var c=this.
|
3353
|
-
`for(var x in c){try{if(x.slice(1,2)=='_'){#{yield `c[x][1]`}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.
|
3377
|
+
`var c=this.__contents__`
|
3378
|
+
`for(var x in c){try{if(x.slice(1,2)=='_'){#{yield `c[x][1]`}};}catch(e){switch(e.__keyword__){case 'next':;break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3354
3379
|
return self
|
3355
3380
|
end
|
3356
3381
|
|
@@ -3362,7 +3387,7 @@ class Hash
|
|
3362
3387
|
# {}.empty? #=> true
|
3363
3388
|
#
|
3364
3389
|
def empty?
|
3365
|
-
`for(var x in this.
|
3390
|
+
`for(var x in this.__contents__){if(x.slice(1,2)=='_'){return false;};}`
|
3366
3391
|
return true
|
3367
3392
|
end
|
3368
3393
|
|
@@ -3381,7 +3406,7 @@ class Hash
|
|
3381
3406
|
# h.fetch(:z) { |k| "No value at #{k.inspect}"} #=> "No value at :z"
|
3382
3407
|
#
|
3383
3408
|
def fetch(key, &block)
|
3384
|
-
`var c=this.
|
3409
|
+
`var c=this.__contents__,k=key.m$hash(),kv=c[k]`
|
3385
3410
|
`if(kv!=null){return kv[1];}`
|
3386
3411
|
return `typeof(block)=='function'?block(key):block`
|
3387
3412
|
end
|
@@ -3400,7 +3425,7 @@ class Hash
|
|
3400
3425
|
# h.has_key?(:z) #=> false
|
3401
3426
|
#
|
3402
3427
|
def has_key?(k)
|
3403
|
-
`!!this.
|
3428
|
+
`!!this.__contents__[k.m$hash()]`
|
3404
3429
|
end
|
3405
3430
|
|
3406
3431
|
# call-seq:
|
@@ -3416,7 +3441,7 @@ class Hash
|
|
3416
3441
|
# h.has_value?(999) #=> false
|
3417
3442
|
#
|
3418
3443
|
def has_value?(value)
|
3419
|
-
`var c=this.
|
3444
|
+
`var c=this.__contents__`
|
3420
3445
|
`for(var x in c){if(x.slice(1,2)=='_'&&c[x][1].m$_eql2(value)){return true;};}`
|
3421
3446
|
return false
|
3422
3447
|
end
|
@@ -3438,7 +3463,7 @@ class Hash
|
|
3438
3463
|
# h.include?(:z) #=> false
|
3439
3464
|
#
|
3440
3465
|
def include?(k)
|
3441
|
-
`!!this.
|
3466
|
+
`!!this.__contents__[k.m$hash()]`
|
3442
3467
|
end
|
3443
3468
|
|
3444
3469
|
# call-seq:
|
@@ -3452,7 +3477,7 @@ class Hash
|
|
3452
3477
|
# h.index(999) #=> nil
|
3453
3478
|
#
|
3454
3479
|
def index(value)
|
3455
|
-
`var c=this.
|
3480
|
+
`var c=this.__contents__`
|
3456
3481
|
`for(var x in c){var kv=c[x];if(x.slice(1,2)=='_'&&kv[1].m$_eql2(value)){return kv[0];};}`
|
3457
3482
|
return nil
|
3458
3483
|
end
|
@@ -3467,8 +3492,8 @@ class Hash
|
|
3467
3492
|
# h.inspect #=> "{:a => 100, :b => 200}"
|
3468
3493
|
#
|
3469
3494
|
def inspect
|
3470
|
-
`var contents=[],c=this.
|
3471
|
-
`for(var x in c){if(x.slice(1,2)=='_'){var kv=c[x];contents.push(kv[0].m$inspect().
|
3495
|
+
`var contents=[],c=this.__contents__`
|
3496
|
+
`for(var x in c){if(x.slice(1,2)=='_'){var kv=c[x];contents.push(kv[0].m$inspect().__value__+' => '+kv[1].m$inspect().__value__);};}`
|
3472
3497
|
return `$q('{'+contents.join(', ')+'}')`
|
3473
3498
|
end
|
3474
3499
|
|
@@ -3483,8 +3508,8 @@ class Hash
|
|
3483
3508
|
# h.invert #=> {100 => :m, 300 => :y, 200 => :d, 0 => :a}
|
3484
3509
|
#
|
3485
3510
|
def invert
|
3486
|
-
`var c=this.
|
3487
|
-
`for(var x in c){if(x.slice(1,2)=='_'){var ckv=c[x],rkv=result.
|
3511
|
+
`var c=this.__contents__,result=c$Hash.m$new()`
|
3512
|
+
`for(var x in c){if(x.slice(1,2)=='_'){var ckv=c[x],rkv=result.__contents__[ckv[1].m$hash()]=[];rkv[0]=ckv[1];rkv[1]=ckv[0]};}`
|
3488
3513
|
return `result`
|
3489
3514
|
end
|
3490
3515
|
|
@@ -3502,7 +3527,7 @@ class Hash
|
|
3502
3527
|
# h.key?(:z) #=> false
|
3503
3528
|
#
|
3504
3529
|
def key?(k)
|
3505
|
-
`!!this.
|
3530
|
+
`!!this.__contents__[k.m$hash()]`
|
3506
3531
|
end
|
3507
3532
|
|
3508
3533
|
# call-seq:
|
@@ -3516,7 +3541,7 @@ class Hash
|
|
3516
3541
|
# h.keys #=> [:a, :b]
|
3517
3542
|
#
|
3518
3543
|
def keys
|
3519
|
-
`var c=this.
|
3544
|
+
`var c=this.__contents__,result=[]`
|
3520
3545
|
`for(var x in c){if(x.slice(1,2)=='_'){result.push(c[x][0]);};}`
|
3521
3546
|
return `result`
|
3522
3547
|
end
|
@@ -3534,7 +3559,7 @@ class Hash
|
|
3534
3559
|
# h.length #=> 0
|
3535
3560
|
#
|
3536
3561
|
def length
|
3537
|
-
`var c=this.
|
3562
|
+
`var c=this.__contents__,result=0`
|
3538
3563
|
`for(var x in c){if(x.slice(1,2)=='_'){result++;};}`
|
3539
3564
|
return `result`
|
3540
3565
|
end
|
@@ -3553,7 +3578,7 @@ class Hash
|
|
3553
3578
|
# h.member?(:z) #=> false
|
3554
3579
|
#
|
3555
3580
|
def member?(k)
|
3556
|
-
`!!this.
|
3581
|
+
`!!this.__contents__[k.m$hash()]`
|
3557
3582
|
end
|
3558
3583
|
|
3559
3584
|
# call-seq:
|
@@ -3572,7 +3597,7 @@ class Hash
|
|
3572
3597
|
#
|
3573
3598
|
# FIX: Doesn't handle loop control keywords
|
3574
3599
|
def merge(other)
|
3575
|
-
`var c=this.
|
3600
|
+
`var c=this.__contents__,o=other.__contents__,result=c$Hash.m$new(),r=result.__contents__`
|
3576
3601
|
`for(var x in c){if(x.slice(1,2)=='_'){r[x]=c[x];};}`
|
3577
3602
|
`for(var x in o){var ckv=c[x],okv=o[x];if(x.slice(1,2)=='_'){typeof(_block)=='function'&&ckv!=null?r[x]=[ckv[0],#{yield(`ckv[0]`,`ckv[1]`,`okv[1]`)}]:r[x]=okv;};}`
|
3578
3603
|
return `result`
|
@@ -3596,7 +3621,7 @@ class Hash
|
|
3596
3621
|
#
|
3597
3622
|
# FIX: Doesn't handle loop control keywords
|
3598
3623
|
def merge!(other)
|
3599
|
-
`var c=this.
|
3624
|
+
`var c=this.__contents__,o=other.__contents__`
|
3600
3625
|
`for(var x in o){var ckv=c[x],okv=o[x];if(x.slice(1,2)=='_'){typeof(_block)=='function'&&ckv!=null?ckv[1]=#{yield(`ckv[0]`,`ckv[1]`,`okv[1]`)}:c[x]=okv;};}`
|
3601
3626
|
return self
|
3602
3627
|
end
|
@@ -3614,8 +3639,8 @@ class Hash
|
|
3614
3639
|
# h #=> {:a => 100, :b => 200, :c => 300}
|
3615
3640
|
#
|
3616
3641
|
def reject
|
3617
|
-
`var c=this.
|
3618
|
-
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&!$T(#{yield(`kv[0]`,`kv[1]`)})){result.
|
3642
|
+
`var c=this.__contents__,result=c$Hash.m$new()`
|
3643
|
+
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&!$T(#{yield(`kv[0]`,`kv[1]`)})){result.__contents__[x]=kv;};}catch(e){switch(e.__keyword__){case 'next':if(!$T(e.__return__)){result.__contents__[x]=kv;};break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3619
3644
|
return `result`
|
3620
3645
|
end
|
3621
3646
|
|
@@ -3633,8 +3658,8 @@ class Hash
|
|
3633
3658
|
# h #=> {:a => 100}
|
3634
3659
|
#
|
3635
3660
|
def reject!
|
3636
|
-
`var c=this.
|
3637
|
-
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&$T(#{yield(`kv[0]`,`kv[1]`)})){u=false;delete(c[x]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.
|
3661
|
+
`var c=this.__contents__,u=true`
|
3662
|
+
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&$T(#{yield(`kv[0]`,`kv[1]`)})){u=false;delete(c[x]);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.__return__)){u=false;delete(c[x]);};break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3638
3663
|
return `u?nil:this`
|
3639
3664
|
end
|
3640
3665
|
|
@@ -3649,8 +3674,8 @@ class Hash
|
|
3649
3674
|
# h #=> {:c => 300, :d => 400}
|
3650
3675
|
#
|
3651
3676
|
def replace(other)
|
3652
|
-
`this.
|
3653
|
-
`var c=this.
|
3677
|
+
`this.__contents__={}`
|
3678
|
+
`var c=this.__contents__,o=other.__contents__`
|
3654
3679
|
`for(var x in o){if(x.slice(1,2)=='_'){c[x]=o[x];};}`
|
3655
3680
|
return self
|
3656
3681
|
end
|
@@ -3667,8 +3692,8 @@ class Hash
|
|
3667
3692
|
# h.select {|k,v| v < 200} #=> [[:a, 100]]
|
3668
3693
|
#
|
3669
3694
|
def select
|
3670
|
-
`var c=this.
|
3671
|
-
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&$T(#{yield(`kv[0]`,`kv[1]`)})){result.push(kv);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.
|
3695
|
+
`var c=this.__contents__,result=[]`
|
3696
|
+
`for(var x in c){try{var kv=c[x];if(x.slice(1,2)=='_'&&$T(#{yield(`kv[0]`,`kv[1]`)})){result.push(kv);};}catch(e){switch(e.__keyword__){case 'next':if($T(e.__return__)){result.push(kv);};break;case 'break':return e.__return__;break;default:throw(e);};};}`
|
3672
3697
|
return `result`
|
3673
3698
|
end
|
3674
3699
|
|
@@ -3686,7 +3711,7 @@ class Hash
|
|
3686
3711
|
# h #=> {}
|
3687
3712
|
#
|
3688
3713
|
def shift
|
3689
|
-
`var c=this.
|
3714
|
+
`var c=this.__contents__,d=this.__default__,result=typeof(d)=='function'?d(nil):d`
|
3690
3715
|
`for(var x in c){if(x.slice(1,2)=='_'){result=[c[x][0],c[x][1]];delete(c[x]);break;};}`
|
3691
3716
|
return `result`
|
3692
3717
|
end
|
@@ -3704,7 +3729,7 @@ class Hash
|
|
3704
3729
|
# h.size #=> 0
|
3705
3730
|
#
|
3706
3731
|
def size
|
3707
|
-
`var c=this.
|
3732
|
+
`var c=this.__contents__,result=0`
|
3708
3733
|
`for(var x in c){if(x.slice(1,2)=='_'){result++;};}`
|
3709
3734
|
return `result`
|
3710
3735
|
end
|
@@ -3723,9 +3748,9 @@ class Hash
|
|
3723
3748
|
#
|
3724
3749
|
# FIX: Doesn't handle loop control keywords
|
3725
3750
|
def sort(&block)
|
3726
|
-
`var c=this.
|
3751
|
+
`var c=this.__contents__,result=[]`
|
3727
3752
|
`for(var x in c){if(x.slice(1,2)=='_'){result.push(c[x]);};}`
|
3728
|
-
return `c$Array.prototype.
|
3753
|
+
return `c$Array.prototype._quick_sort.call(result,0,result.length,block)`
|
3729
3754
|
end
|
3730
3755
|
|
3731
3756
|
# call-seq:
|
@@ -3743,7 +3768,7 @@ class Hash
|
|
3743
3768
|
# h #=> {:a => 150, :b => 200, :c => 300}
|
3744
3769
|
#
|
3745
3770
|
def store(k,v)
|
3746
|
-
`this.
|
3771
|
+
`this.__contents__[k.m$hash()]=[k,v]`
|
3747
3772
|
return `v`
|
3748
3773
|
end
|
3749
3774
|
|
@@ -3757,7 +3782,7 @@ class Hash
|
|
3757
3782
|
# h.to_a #=> [[:a, 100], [:b, 200]]
|
3758
3783
|
#
|
3759
3784
|
def to_a
|
3760
|
-
`var c=this.
|
3785
|
+
`var c=this.__contents__,result=[]`
|
3761
3786
|
`for(var x in c){if(x.slice(1,2)=='_'){result.push(c[x]);};}`
|
3762
3787
|
return `result`
|
3763
3788
|
end
|
@@ -3779,7 +3804,7 @@ class Hash
|
|
3779
3804
|
# <tt>Array#join</tt> with the default separator.
|
3780
3805
|
#
|
3781
3806
|
def to_s
|
3782
|
-
`var c=this.
|
3807
|
+
`var c=this.__contents__,result=[]`
|
3783
3808
|
`for(var x in c){if(x.slice(1,2)=='_'){result.push(c[x]);};}`
|
3784
3809
|
return `c$Array.prototype.m$join.call(result)`
|
3785
3810
|
end
|
@@ -3802,7 +3827,7 @@ class Hash
|
|
3802
3827
|
#
|
3803
3828
|
# FIX: Doesn't handle loop control keywords
|
3804
3829
|
def update(other)
|
3805
|
-
`var c=this.
|
3830
|
+
`var c=this.__contents__,o=other.__contents__`
|
3806
3831
|
`for(var x in o){var ckv=c[x],okv=o[x];if(x.slice(1,2)=='_'){typeof(_block)=='function'&&ckv!=null?ckv[1]=#{yield(`ckv[0]`,`ckv[1]`,`okv[1]`)}:c[x]=okv;};}`
|
3807
3832
|
return self
|
3808
3833
|
end
|
@@ -3820,8 +3845,8 @@ class Hash
|
|
3820
3845
|
# h.value?(999) #=> false
|
3821
3846
|
#
|
3822
3847
|
def value?(value)
|
3823
|
-
`var c=this.
|
3824
|
-
`for(var x in this.
|
3848
|
+
`var c=this.__contents__`
|
3849
|
+
`for(var x in this.__contents__){if(x.slice(1,2)=='_'&&c[x][1].m$_eql2(value)){return true;};}`
|
3825
3850
|
return false
|
3826
3851
|
end
|
3827
3852
|
|
@@ -3836,7 +3861,7 @@ class Hash
|
|
3836
3861
|
# h.values #=> [100, 200]
|
3837
3862
|
#
|
3838
3863
|
def values
|
3839
|
-
`var c=this.
|
3864
|
+
`var c=this.__contents__,result=[]`
|
3840
3865
|
`for(var x in c){if(x.slice(1,2)=='_'){result.push(c[x][1]);};}`
|
3841
3866
|
return `result`
|
3842
3867
|
end
|
@@ -3852,7 +3877,7 @@ class Hash
|
|
3852
3877
|
# h.values_at(:a,:c) #=> [100,300]
|
3853
3878
|
#
|
3854
3879
|
def values_at(*args)
|
3855
|
-
`for(var i=0,l=args.length,c=this.
|
3880
|
+
`for(var i=0,l=args.length,c=this.__contents__,d=this.__default__,result=[];i<l;++i){var h=args[i].m$hash(),kv=c[h];result.push(kv?kv[1]:(typeof(d)=='function'?d(this,args[i]):d))}`
|
3856
3881
|
return `result`
|
3857
3882
|
end
|
3858
3883
|
end
|
@@ -3863,7 +3888,7 @@ end
|
|
3863
3888
|
#
|
3864
3889
|
class MatchData
|
3865
3890
|
def initialize # :nodoc:
|
3866
|
-
`this.
|
3891
|
+
`this.__captures__=[]`
|
3867
3892
|
end
|
3868
3893
|
|
3869
3894
|
# call-seq:
|
@@ -3885,7 +3910,7 @@ class MatchData
|
|
3885
3910
|
# m[-3, 2] #=> ["X", "113"]
|
3886
3911
|
#
|
3887
3912
|
def [](*args)
|
3888
|
-
`c$Array.prototype.m$_brac.apply(this.
|
3913
|
+
`c$Array.prototype.m$_brac.apply(this.__captures__,args)`
|
3889
3914
|
end
|
3890
3915
|
|
3891
3916
|
# FIX: Incomplete
|
@@ -3905,7 +3930,7 @@ class MatchData
|
|
3905
3930
|
# m[3] #=> "8"
|
3906
3931
|
#
|
3907
3932
|
def captures
|
3908
|
-
`this.
|
3933
|
+
`this.__captures__.slice(1)`
|
3909
3934
|
end
|
3910
3935
|
|
3911
3936
|
# FIX: Incomplete
|
@@ -3923,11 +3948,11 @@ class MatchData
|
|
3923
3948
|
# m.length #=> 5
|
3924
3949
|
#
|
3925
3950
|
def length
|
3926
|
-
`this.
|
3951
|
+
`this.__captures__.length`
|
3927
3952
|
end
|
3928
3953
|
|
3929
3954
|
def inspect # :nodoc:
|
3930
|
-
`c$Object.prototype.m$
|
3955
|
+
`c$Object.prototype.m$to_s.apply(this)`
|
3931
3956
|
end
|
3932
3957
|
|
3933
3958
|
# FIX: Incomplete
|
@@ -3944,7 +3969,7 @@ class MatchData
|
|
3944
3969
|
# m.post_match #=> ": The Movie"
|
3945
3970
|
#
|
3946
3971
|
def post_match
|
3947
|
-
`this.
|
3972
|
+
`this.__post__`
|
3948
3973
|
end
|
3949
3974
|
|
3950
3975
|
# call-seq:
|
@@ -3957,7 +3982,7 @@ class MatchData
|
|
3957
3982
|
# m.pre_match #=> "T"
|
3958
3983
|
#
|
3959
3984
|
def pre_match
|
3960
|
-
`this.
|
3985
|
+
`this.__pre__`
|
3961
3986
|
end
|
3962
3987
|
|
3963
3988
|
# FIX: Incomplete
|
@@ -3975,7 +4000,7 @@ class MatchData
|
|
3975
4000
|
# m.size #=> 5
|
3976
4001
|
#
|
3977
4002
|
def size
|
3978
|
-
`this.
|
4003
|
+
`this.__captures__.length`
|
3979
4004
|
end
|
3980
4005
|
|
3981
4006
|
# call-seq:
|
@@ -3991,7 +4016,7 @@ class MatchData
|
|
3991
4016
|
# m2.string #=> "THX1138."
|
3992
4017
|
#
|
3993
4018
|
def string
|
3994
|
-
`$q(this.
|
4019
|
+
`$q(this.__string__)`
|
3995
4020
|
end
|
3996
4021
|
|
3997
4022
|
# call-seq:
|
@@ -4004,7 +4029,7 @@ class MatchData
|
|
4004
4029
|
# m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
4005
4030
|
#
|
4006
4031
|
def to_a
|
4007
|
-
`this.
|
4032
|
+
`this.__captures__`
|
4008
4033
|
end
|
4009
4034
|
|
4010
4035
|
# call-seq:
|
@@ -4017,7 +4042,7 @@ class MatchData
|
|
4017
4042
|
# m.to_s #=> "HX1138"
|
4018
4043
|
#
|
4019
4044
|
def to_s
|
4020
|
-
`this.
|
4045
|
+
`this.__captures__[0]`
|
4021
4046
|
end
|
4022
4047
|
|
4023
4048
|
# FIX: Incomplete
|
@@ -4104,6 +4129,10 @@ class NilClass
|
|
4104
4129
|
0
|
4105
4130
|
end
|
4106
4131
|
|
4132
|
+
def to_proc # :nodoc:
|
4133
|
+
nil
|
4134
|
+
end
|
4135
|
+
|
4107
4136
|
# call-seq:
|
4108
4137
|
# nil.to_s -> ''
|
4109
4138
|
#
|
@@ -4336,7 +4365,7 @@ class Numeric
|
|
4336
4365
|
# ?a.chr #=> "a"
|
4337
4366
|
#
|
4338
4367
|
def chr
|
4339
|
-
|
4368
|
+
`$q(String.fromCharCode(parseInt(this)))`
|
4340
4369
|
end
|
4341
4370
|
|
4342
4371
|
# call-seq:
|
@@ -4382,7 +4411,7 @@ class Numeric
|
|
4382
4411
|
# 1..
|
4383
4412
|
#
|
4384
4413
|
def downto(limit)
|
4385
|
-
`for(var i=this.valueOf();i>=limit;--i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
4414
|
+
`for(var i=this.valueOf();i>=limit;--i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':++i;break;default:throw(e);};};}`
|
4386
4415
|
return self
|
4387
4416
|
end
|
4388
4417
|
|
@@ -4542,7 +4571,7 @@ class Numeric
|
|
4542
4571
|
#
|
4543
4572
|
def step(limit, step)
|
4544
4573
|
`var i=this.valueOf()`
|
4545
|
-
`if(step>0){if(i<limit){for(;limit>=i;i+=step){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
4574
|
+
`if(step>0){if(i<limit){for(;limit>=i;i+=step){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':i-=step;break;default:throw(e);};};};};}else{if(i>limit){for(;limit<=i;i+=step){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':i-=step;break;default:throw(e);};}};;};}`
|
4546
4575
|
return self
|
4547
4576
|
end
|
4548
4577
|
|
@@ -4579,7 +4608,7 @@ class Numeric
|
|
4579
4608
|
# 4
|
4580
4609
|
#
|
4581
4610
|
def times
|
4582
|
-
`for(var i=0,l=this.valueOf();i<l;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
4611
|
+
`for(var i=0,l=this.valueOf();i<l;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};}}`
|
4583
4612
|
return self
|
4584
4613
|
end
|
4585
4614
|
|
@@ -4661,7 +4690,7 @@ class Numeric
|
|
4661
4690
|
# 100..
|
4662
4691
|
#
|
4663
4692
|
def upto(limit)
|
4664
|
-
`for(var i=this.valueOf();i<=limit;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.
|
4693
|
+
`for(var i=this.valueOf();i<=limit;++i){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};}`
|
4665
4694
|
return self
|
4666
4695
|
end
|
4667
4696
|
|
@@ -4697,11 +4726,19 @@ class Proc
|
|
4697
4726
|
# Creates a new +Proc+ object, bound to the current context.
|
4698
4727
|
#
|
4699
4728
|
def initialize(func)
|
4700
|
-
`this.
|
4729
|
+
`this.__block__=func`
|
4730
|
+
`this.__block__.__id__=func.__id__||Red.id++`
|
4731
|
+
`this.__id__=this.__block__.__id__`
|
4701
4732
|
end
|
4702
4733
|
|
4703
|
-
#
|
4704
|
-
|
4734
|
+
# call-seq:
|
4735
|
+
# prc == other => true or false
|
4736
|
+
#
|
4737
|
+
# Returns +true+ if _prc_ and _other_ are the same object, +false+
|
4738
|
+
# otherwise.
|
4739
|
+
#
|
4740
|
+
def ==(other)
|
4741
|
+
`this.__id__==other.__id__`
|
4705
4742
|
end
|
4706
4743
|
|
4707
4744
|
# call-seq:
|
@@ -4718,7 +4755,7 @@ class Proc
|
|
4718
4755
|
# proc[4] #=> 400
|
4719
4756
|
#
|
4720
4757
|
def []()
|
4721
|
-
`this.
|
4758
|
+
`this.__block__.apply(this,arguments)`
|
4722
4759
|
end
|
4723
4760
|
|
4724
4761
|
# FIX: Incomplete
|
@@ -4740,7 +4777,7 @@ class Proc
|
|
4740
4777
|
# proc.call(4) #=> 400
|
4741
4778
|
#
|
4742
4779
|
def call
|
4743
|
-
`this.
|
4780
|
+
`this.__block__.apply(this,arguments)`
|
4744
4781
|
end
|
4745
4782
|
|
4746
4783
|
# call-seq:
|
@@ -4804,9 +4841,9 @@ class Range
|
|
4804
4841
|
# it will be excluded.
|
4805
4842
|
#
|
4806
4843
|
def initialize(start,finish,exclusive=false)
|
4807
|
-
`this.
|
4808
|
-
`this.
|
4809
|
-
`this.
|
4844
|
+
`this.__start__=start`
|
4845
|
+
`this.__end__=finish`
|
4846
|
+
`this.__exclusive__=exclusive`
|
4810
4847
|
end
|
4811
4848
|
|
4812
4849
|
# call-seq:
|
@@ -4822,7 +4859,7 @@ class Range
|
|
4822
4859
|
#
|
4823
4860
|
def ==(object)
|
4824
4861
|
`if(object.constructor!==c$Range){return false;}`
|
4825
|
-
`this.
|
4862
|
+
`this.__start__.m$_eql2(object.__start__)&&this.__end__.m$_eql2(object.__end__)&&this.__exclusive__==object.__exclusive__`
|
4826
4863
|
end
|
4827
4864
|
|
4828
4865
|
# call-seq:
|
@@ -4845,8 +4882,8 @@ class Range
|
|
4845
4882
|
# high
|
4846
4883
|
#
|
4847
4884
|
def ===(obj)
|
4848
|
-
`var s=#{obj <=> `this.
|
4849
|
-
`s==0||s==1?(this.
|
4885
|
+
`var s=#{obj <=> `this.__start__`},e=#{obj <=> `this.__end__`}`
|
4886
|
+
`s==0||s==1?(this.__exclusive__?e==-1:e==-1||e==0):false`
|
4850
4887
|
end
|
4851
4888
|
|
4852
4889
|
# call-seq:
|
@@ -4858,13 +4895,13 @@ class Range
|
|
4858
4895
|
# (1..10).begin #=> 1
|
4859
4896
|
#
|
4860
4897
|
def begin
|
4861
|
-
`this.
|
4898
|
+
`this.__start__`
|
4862
4899
|
end
|
4863
4900
|
|
4864
4901
|
# FIX: Incomplete
|
4865
4902
|
def each
|
4866
|
-
`var start=this.
|
4867
|
-
`if(typeof(start)=='number'&&typeof(end)=='number'){if(!this.
|
4903
|
+
`var start=this.__start__,end=this.__end__`
|
4904
|
+
`if(typeof(start)=='number'&&typeof(end)=='number'){if(!this.__exclusive__){end++;};for(var i=start;i<end;i++){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':--i;break;default:throw(e);};};};}`
|
4868
4905
|
return self
|
4869
4906
|
end
|
4870
4907
|
|
@@ -4878,7 +4915,7 @@ class Range
|
|
4878
4915
|
# (1...10).end #=> 10
|
4879
4916
|
#
|
4880
4917
|
def end()
|
4881
|
-
`this.
|
4918
|
+
`this.__end__`
|
4882
4919
|
end
|
4883
4920
|
|
4884
4921
|
# call-seq:
|
@@ -4887,7 +4924,7 @@ class Range
|
|
4887
4924
|
# Returns +true+ if _rng_ excludes its end value.
|
4888
4925
|
#
|
4889
4926
|
def exclude_end?
|
4890
|
-
`this.
|
4927
|
+
`this.__exclusive__`
|
4891
4928
|
end
|
4892
4929
|
|
4893
4930
|
# call-seq:
|
@@ -4903,7 +4940,7 @@ class Range
|
|
4903
4940
|
#
|
4904
4941
|
def eql?(object)
|
4905
4942
|
`if(object.constructor!==c$Range){return false;}`
|
4906
|
-
`this.
|
4943
|
+
`this.__start__.m$eql_bool(object.__start__)&&this.__end__.m$eql_bool(object.__end__)&&this.__exclusive__==object.__exclusive__`
|
4907
4944
|
end
|
4908
4945
|
|
4909
4946
|
# call-seq:
|
@@ -4915,7 +4952,7 @@ class Range
|
|
4915
4952
|
# (1..10).first #=> 1
|
4916
4953
|
#
|
4917
4954
|
def first
|
4918
|
-
`this.
|
4955
|
+
`this.__start__`
|
4919
4956
|
end
|
4920
4957
|
|
4921
4958
|
# FIX: Incomplete
|
@@ -4933,8 +4970,8 @@ class Range
|
|
4933
4970
|
# (1...10).include?(10) #=> false
|
4934
4971
|
#
|
4935
4972
|
def include?(obj)
|
4936
|
-
`var s=#{obj <=> `this.
|
4937
|
-
`s==0||s==1?(this.
|
4973
|
+
`var s=#{obj <=> `this.__start__`},e=#{obj <=> `this.__end__`}`
|
4974
|
+
`s==0||s==1?(this.__exclusive__?e==-1:e==-1||e==0):false`
|
4938
4975
|
end
|
4939
4976
|
|
4940
4977
|
# call-seq:
|
@@ -4944,7 +4981,7 @@ class Range
|
|
4944
4981
|
# and end objects).
|
4945
4982
|
#
|
4946
4983
|
def inspect
|
4947
|
-
`$q(''+this.
|
4984
|
+
`$q(''+this.__start__.m$inspect()+(this.__exclusive__?'...':'..')+this.__end__.m$inspect())`
|
4948
4985
|
end
|
4949
4986
|
|
4950
4987
|
# call-seq:
|
@@ -4957,7 +4994,7 @@ class Range
|
|
4957
4994
|
# (1...10).last #=> 10
|
4958
4995
|
#
|
4959
4996
|
def last
|
4960
|
-
`this.
|
4997
|
+
`this.__end__`
|
4961
4998
|
end
|
4962
4999
|
|
4963
5000
|
# call-seq:
|
@@ -4971,8 +5008,8 @@ class Range
|
|
4971
5008
|
# (1...10).member?(10) #=> false
|
4972
5009
|
#
|
4973
5010
|
def member?(obj)
|
4974
|
-
`var s=#{obj <=> `this.
|
4975
|
-
`s==0||s==1?(this.
|
5011
|
+
`var s=#{obj <=> `this.__start__`},e=#{obj <=> `this.__end__`}`
|
5012
|
+
`s==0||s==1?(this.__exclusive__?e==-1:e==-1||e==0):false`
|
4976
5013
|
end
|
4977
5014
|
|
4978
5015
|
# FIX: Incomplete
|
@@ -4985,7 +5022,7 @@ class Range
|
|
4985
5022
|
# Converts _rng_ to a printable form.
|
4986
5023
|
#
|
4987
5024
|
def to_s
|
4988
|
-
`$q(''+this.
|
5025
|
+
`$q(''+this.__start__+(this.__exclusive__?'...':'..')+this.__end__)`
|
4989
5026
|
end
|
4990
5027
|
end
|
4991
5028
|
|
@@ -5038,7 +5075,7 @@ class Regexp
|
|
5038
5075
|
# Regexp.escape('\\*?{}.') #=> \\\\\*\?\{\}\.
|
5039
5076
|
#
|
5040
5077
|
def self.escape(str)
|
5041
|
-
`$q(str.
|
5078
|
+
`$q(str.__value__.replace(/([-.*+?^${}()|[\\]\\/\\\\])/g, '\\\\$1'))`
|
5042
5079
|
end
|
5043
5080
|
|
5044
5081
|
# FIX: Incomplete
|
@@ -5056,7 +5093,7 @@ class Regexp
|
|
5056
5093
|
# Regexp.quote('\\*?{}.') #=> \\\\\*\?\{\}\.
|
5057
5094
|
#
|
5058
5095
|
def self.quote(str)
|
5059
|
-
`str.
|
5096
|
+
`str.__value__.replace(/([-.*+?^${}()|[\\]\\/\\\\])/g, '\\\\$1')`
|
5060
5097
|
end
|
5061
5098
|
|
5062
5099
|
# FIX: Incomplete
|
@@ -5079,9 +5116,9 @@ class Regexp
|
|
5079
5116
|
# r3 = Regexp.new(r2) #=> /cat/i
|
5080
5117
|
#
|
5081
5118
|
def initialize(regexp, options)
|
5082
|
-
`switch(options){case 0:this.
|
5083
|
-
`this.
|
5084
|
-
`this.
|
5119
|
+
`switch(options){case 0:this.__options__='';break;case 1:this.__options__='i';break;case 2:this.__options__='x';break;case 3:this.__options__='ix';break;case 4:this.__options__='s';break;case 5:this.__options__='si';break;case 6:this.__options__='sx';break;case 7:this.__options__='six';break;default:this.__options__=options?'i':'';}`
|
5120
|
+
`this.__source__=regexp.__value__||regexp`
|
5121
|
+
`this.__value__=new(RegExp)(this.__source__,'m'+(/i/.test(this.__options__)?'i':''))`
|
5085
5122
|
end
|
5086
5123
|
|
5087
5124
|
# call-seq:
|
@@ -5095,7 +5132,7 @@ class Regexp
|
|
5095
5132
|
# /abc/ == /abc/i #=> false
|
5096
5133
|
#
|
5097
5134
|
def ==(rxp)
|
5098
|
-
`this.
|
5135
|
+
`this.__source__===rxp.__source__&&this.__options__===rxp.__options__`
|
5099
5136
|
end
|
5100
5137
|
|
5101
5138
|
# call-seq:
|
@@ -5116,9 +5153,9 @@ class Regexp
|
|
5116
5153
|
# FIX: Incomplete
|
5117
5154
|
def ===(string)
|
5118
5155
|
`var c=$u,result=c$MatchData.m$new()`
|
5119
|
-
`if(!$T(c=string.
|
5120
|
-
`for(var i=0,l=c.length;i<l;++i){result.
|
5121
|
-
`result.
|
5156
|
+
`if(!$T(c=string.__value__.match(this.__value__))){return nil;}`
|
5157
|
+
`for(var i=0,l=c.length;i<l;++i){result.__captures__[i]=$q(c[i])}`
|
5158
|
+
`result.__string__=string.__value__`
|
5122
5159
|
return `result`
|
5123
5160
|
end
|
5124
5161
|
|
@@ -5134,9 +5171,9 @@ class Regexp
|
|
5134
5171
|
# FIX: Incomplete
|
5135
5172
|
def =~(string)
|
5136
5173
|
`var c=$u,result=c$MatchData.m$new()`
|
5137
|
-
`if(!$T(c=string.
|
5138
|
-
`for(var i=0,l=c.length;i<l;++i){result.
|
5139
|
-
`result.
|
5174
|
+
`if(!$T(c=string.__value__.match(this.__value__))){return nil;}`
|
5175
|
+
`for(var i=0,l=c.length;i<l;++i){result.__captures__[i]=$q(c[i])}`
|
5176
|
+
`result.__string__=string.__value__`
|
5140
5177
|
return `result`
|
5141
5178
|
end
|
5142
5179
|
|
@@ -5150,7 +5187,7 @@ class Regexp
|
|
5150
5187
|
# Returns the status of the +IGNORECASE+ flag.
|
5151
5188
|
#
|
5152
5189
|
def casefold?
|
5153
|
-
`/i/.test(this.
|
5190
|
+
`/i/.test(this.__options__)`
|
5154
5191
|
end
|
5155
5192
|
|
5156
5193
|
# call-seq:
|
@@ -5164,7 +5201,7 @@ class Regexp
|
|
5164
5201
|
# /abc/.eql? /abc/i #=> false
|
5165
5202
|
#
|
5166
5203
|
def eql?(rxp)
|
5167
|
-
`this.
|
5204
|
+
`this.__source__===rxp.__source__&&this.__options__===rxp.__options__`
|
5168
5205
|
end
|
5169
5206
|
|
5170
5207
|
def hash # :nodoc:
|
@@ -5192,11 +5229,11 @@ class Regexp
|
|
5192
5229
|
#
|
5193
5230
|
def match(string)
|
5194
5231
|
`var c=$u,result=c$MatchData.m$new()`
|
5195
|
-
`if(!$T(c=string.
|
5196
|
-
`for(var i=0,l=c.length;i<l;++i){result.
|
5197
|
-
`result.
|
5198
|
-
`result.
|
5199
|
-
`result.
|
5232
|
+
`if(!$T(c=string.__value__.match(this.__value__))){return nil;}`
|
5233
|
+
`for(var i=0,l=c.length;i<l;++i){result.__captures__[i]=$q(c[i])}`
|
5234
|
+
`result.__string__=string.__value__`
|
5235
|
+
`result.__pre__=RegExp.leftContext`
|
5236
|
+
`result.__post__=RegExp.rightContext`
|
5200
5237
|
return `result`
|
5201
5238
|
end
|
5202
5239
|
|
@@ -5220,9 +5257,9 @@ class Regexp
|
|
5220
5257
|
#
|
5221
5258
|
def options
|
5222
5259
|
`var result=0`
|
5223
|
-
`if(/i/.test(this.
|
5224
|
-
`if(/x/.test(this.
|
5225
|
-
`if(/s/.test(this.
|
5260
|
+
`if(/i/.test(this.__options__)){result+=1}`
|
5261
|
+
`if(/x/.test(this.__options__)){result+=2}`
|
5262
|
+
`if(/s/.test(this.__options__)){result+=4}`
|
5226
5263
|
return `result`
|
5227
5264
|
end
|
5228
5265
|
|
@@ -5234,7 +5271,7 @@ class Regexp
|
|
5234
5271
|
# /ab+c/i.source #=> "ab+c"
|
5235
5272
|
#
|
5236
5273
|
def source
|
5237
|
-
`$q(this.
|
5274
|
+
`$q(this.__source__)`
|
5238
5275
|
end
|
5239
5276
|
|
5240
5277
|
# call-seq:
|
@@ -5247,8 +5284,8 @@ class Regexp
|
|
5247
5284
|
# /ab+c/i.to_s #=> "(?i-mx:ab+c)"
|
5248
5285
|
#
|
5249
5286
|
def to_s
|
5250
|
-
`var o=this.
|
5251
|
-
`$q('(?'+o+(c[0]=='mix'?'':'-')+(c[1]?'':'m')+(c[2]?'':'i')+(c[3]?'':'x')+':'+this.
|
5287
|
+
`var o=this.__options__.replace('s','m'),c=o.match(/(m)?(i)?(x)?/)`
|
5288
|
+
`$q('(?'+o+(c[0]=='mix'?'':'-')+(c[1]?'':'m')+(c[2]?'':'i')+(c[3]?'':'x')+':'+this.__source__+')')`
|
5252
5289
|
end
|
5253
5290
|
end
|
5254
5291
|
|
@@ -5265,7 +5302,7 @@ class String
|
|
5265
5302
|
# Returns a new string object containing a copy of _str_.
|
5266
5303
|
#
|
5267
5304
|
def initialize(string = `''`)
|
5268
|
-
`this.
|
5305
|
+
`this.__value__=string.__value__||string`
|
5269
5306
|
end
|
5270
5307
|
|
5271
5308
|
# call-seq:
|
@@ -5293,7 +5330,7 @@ class String
|
|
5293
5330
|
# 'abc ' * 3 #=> "abc abc abc "
|
5294
5331
|
#
|
5295
5332
|
def *(n)
|
5296
|
-
`for(var i=0,str=this.
|
5333
|
+
`for(var i=0,str=this.__value__,result='';i<n;++i){result+=str;}`
|
5297
5334
|
return `$q(result)`
|
5298
5335
|
end
|
5299
5336
|
|
@@ -5306,7 +5343,7 @@ class String
|
|
5306
5343
|
# 'abc' + 'def' #=> 'abcdef'
|
5307
5344
|
#
|
5308
5345
|
def +(str)
|
5309
|
-
`$q(this.
|
5346
|
+
`$q(this.__value__ + str.__value__)`
|
5310
5347
|
end
|
5311
5348
|
|
5312
5349
|
# call-seq:
|
@@ -5325,7 +5362,7 @@ class String
|
|
5325
5362
|
# s << 103 << 104 #=> "abcdefgh"
|
5326
5363
|
#
|
5327
5364
|
def <<(obj)
|
5328
|
-
`this.
|
5365
|
+
`this.__value__+=(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__)`
|
5329
5366
|
return self
|
5330
5367
|
end
|
5331
5368
|
|
@@ -5350,7 +5387,7 @@ class String
|
|
5350
5387
|
#
|
5351
5388
|
def <=>(str)
|
5352
5389
|
`if(str.m$class()!=c$String){return nil;}`
|
5353
|
-
`var tv=this.
|
5390
|
+
`var tv=this.__value__,sv=str.__value__`
|
5354
5391
|
`if(tv>sv){return 1;}`
|
5355
5392
|
`if(tv==sv){return 0;}`
|
5356
5393
|
`if(tv<sv){return -1;}`
|
@@ -5414,7 +5451,7 @@ class String
|
|
5414
5451
|
# '123ABC'.capitalize #=> "123abc"
|
5415
5452
|
#
|
5416
5453
|
def capitalize
|
5417
|
-
`var v=this.
|
5454
|
+
`var v=this.__value__`
|
5418
5455
|
`$q(v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase())`
|
5419
5456
|
end
|
5420
5457
|
|
@@ -5431,9 +5468,9 @@ class String
|
|
5431
5468
|
# s #=> "Abcdef"
|
5432
5469
|
#
|
5433
5470
|
def capitalize!
|
5434
|
-
`var v=this.
|
5435
|
-
`this.
|
5436
|
-
return `v==this.
|
5471
|
+
`var v=this.__value__`
|
5472
|
+
`this.__value__=v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase()`
|
5473
|
+
return `v==this.__value__?nil:this`
|
5437
5474
|
end
|
5438
5475
|
|
5439
5476
|
# call-seq:
|
@@ -5448,7 +5485,7 @@ class String
|
|
5448
5485
|
#
|
5449
5486
|
def casecmp(str)
|
5450
5487
|
`if(str.m$class()!=c$String){return nil;}`
|
5451
|
-
`var tv=this.
|
5488
|
+
`var tv=this.__value__.toLowerCase(),sv=str.__value__.toLowerCase()`
|
5452
5489
|
`if(tv>sv){return 1;}`
|
5453
5490
|
`if(tv==sv){return 0;}`
|
5454
5491
|
`if(tv<sv){return -1;}`
|
@@ -5491,7 +5528,7 @@ class String
|
|
5491
5528
|
# a.concat(103).concat(104) #=> "abcdefgh"
|
5492
5529
|
#
|
5493
5530
|
def concat(obj)
|
5494
|
-
`this.
|
5531
|
+
`this.__value__+=(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__)`
|
5495
5532
|
return self
|
5496
5533
|
end
|
5497
5534
|
|
@@ -5520,7 +5557,7 @@ class String
|
|
5520
5557
|
# 'aBCDEf'.downcase #=> "abcdef"
|
5521
5558
|
#
|
5522
5559
|
def downcase
|
5523
|
-
`$q(this.
|
5560
|
+
`$q(this.__value__.toLowerCase())`
|
5524
5561
|
end
|
5525
5562
|
|
5526
5563
|
# call-seq:
|
@@ -5536,9 +5573,9 @@ class String
|
|
5536
5573
|
# s #=> "abcdef"
|
5537
5574
|
#
|
5538
5575
|
def downcase!
|
5539
|
-
`var v=this.
|
5540
|
-
`this.
|
5541
|
-
return `v==this.
|
5576
|
+
`var v=this.__value__`
|
5577
|
+
`this.__value__=v.toLowerCase()`
|
5578
|
+
return `v==this.__value__?nil:this`
|
5542
5579
|
end
|
5543
5580
|
|
5544
5581
|
# FIX: Incomplete
|
@@ -5562,7 +5599,7 @@ class String
|
|
5562
5599
|
# ''.empty? #=> true
|
5563
5600
|
#
|
5564
5601
|
def empty?
|
5565
|
-
`this.
|
5602
|
+
`this.__value__==''`
|
5566
5603
|
end
|
5567
5604
|
|
5568
5605
|
# call-seq:
|
@@ -5572,7 +5609,7 @@ class String
|
|
5572
5609
|
#
|
5573
5610
|
def eql?(str)
|
5574
5611
|
`if(str.m$class()!=c$String){return false;}`
|
5575
|
-
`this.
|
5612
|
+
`this.__value__==str.__value__`
|
5576
5613
|
end
|
5577
5614
|
|
5578
5615
|
# FIX: Incomplete
|
@@ -5584,7 +5621,7 @@ class String
|
|
5584
5621
|
end
|
5585
5622
|
|
5586
5623
|
def hash # :nodoc:
|
5587
|
-
`'q_'+this.
|
5624
|
+
`'q_'+this.__value__`
|
5588
5625
|
end
|
5589
5626
|
|
5590
5627
|
# call-seq:
|
@@ -5600,7 +5637,7 @@ class String
|
|
5600
5637
|
# 'abcdef'.hex #=> 0
|
5601
5638
|
#
|
5602
5639
|
def hex
|
5603
|
-
`var result=parseInt(this.
|
5640
|
+
`var result=parseInt(this.__value__,16)`
|
5604
5641
|
return `result.toString()=='NaN'?0:result`
|
5605
5642
|
end
|
5606
5643
|
|
@@ -5615,7 +5652,7 @@ class String
|
|
5615
5652
|
# 'abcdef'.include?(?c) #=> true
|
5616
5653
|
#
|
5617
5654
|
def include?(obj)
|
5618
|
-
`new(RegExp)(typeof(obj)=='number'?String.fromCharCode(obj):obj.
|
5655
|
+
`new(RegExp)(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__.replace(/([-.*+?^${}()|[\\]\\/\\\\])/g, '\\\\$1')).test(this.__value__)`
|
5619
5656
|
end
|
5620
5657
|
|
5621
5658
|
# FIX: Incomplete
|
@@ -5628,7 +5665,7 @@ class String
|
|
5628
5665
|
|
5629
5666
|
# FIX: Incomplete
|
5630
5667
|
def inspect
|
5631
|
-
`$q('"'+this.
|
5668
|
+
`$q('"'+this.__value__.replace(/\\\\/g,'\\\\\\\\').replace(/"/g,'\\\\"')+'"')`
|
5632
5669
|
end
|
5633
5670
|
|
5634
5671
|
# call-seq:
|
@@ -5641,7 +5678,7 @@ class String
|
|
5641
5678
|
# 'abcdef'.intern #=> :abcdef
|
5642
5679
|
#
|
5643
5680
|
def intern
|
5644
|
-
`$s(this.
|
5681
|
+
`$s(this.__value__)`
|
5645
5682
|
end
|
5646
5683
|
|
5647
5684
|
# call-seq:
|
@@ -5654,7 +5691,7 @@ class String
|
|
5654
5691
|
# 'ab\ncd'.length #=> 5
|
5655
5692
|
#
|
5656
5693
|
def length
|
5657
|
-
`this.
|
5694
|
+
`this.__value__.length`
|
5658
5695
|
end
|
5659
5696
|
|
5660
5697
|
# FIX: Incomplete
|
@@ -5670,7 +5707,7 @@ class String
|
|
5670
5707
|
# '\tabcdef'.lstrip #=> "abcdef"
|
5671
5708
|
#
|
5672
5709
|
def lstrip
|
5673
|
-
`$q(this.
|
5710
|
+
`$q(this.__value__.replace(/^\\s*/,''))`
|
5674
5711
|
end
|
5675
5712
|
|
5676
5713
|
# call-seq:
|
@@ -5686,9 +5723,9 @@ class String
|
|
5686
5723
|
# s #=> "abcdef"
|
5687
5724
|
#
|
5688
5725
|
def lstrip!
|
5689
|
-
`var v=this.
|
5690
|
-
`this.
|
5691
|
-
return `this.
|
5726
|
+
`var v=this.__value__`
|
5727
|
+
`this.__value__=v.replace(/^\\s*/,'')`
|
5728
|
+
return `this.__value__==v?nil:this`
|
5692
5729
|
end
|
5693
5730
|
|
5694
5731
|
# call-seq:
|
@@ -5703,7 +5740,7 @@ class String
|
|
5703
5740
|
# 'abcdee'.match('xx') #=> nil
|
5704
5741
|
#
|
5705
5742
|
def match(pattern)
|
5706
|
-
`$r(pattern.
|
5743
|
+
`$r(pattern.__source__||pattern.__value__,pattern.__options__).m$match(this)`
|
5707
5744
|
end
|
5708
5745
|
|
5709
5746
|
# call-seq:
|
@@ -5727,7 +5764,7 @@ class String
|
|
5727
5764
|
# 'ZZZ9999'.next #=> 'AAAA0000'
|
5728
5765
|
#
|
5729
5766
|
def next
|
5730
|
-
`var v=this.
|
5767
|
+
`var v=this.__value__`
|
5731
5768
|
`if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
|
5732
5769
|
`if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
|
5733
5770
|
`for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
|
@@ -5743,12 +5780,12 @@ class String
|
|
5743
5780
|
# <tt>String#next</tt> for details.
|
5744
5781
|
#
|
5745
5782
|
def next!
|
5746
|
-
`var v=this.
|
5783
|
+
`var v=this.__value__`
|
5747
5784
|
`if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
|
5748
5785
|
`if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
|
5749
5786
|
`for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
|
5750
5787
|
`if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
|
5751
|
-
`this.
|
5788
|
+
`this.__value__=result`
|
5752
5789
|
return self
|
5753
5790
|
end
|
5754
5791
|
|
@@ -5765,7 +5802,7 @@ class String
|
|
5765
5802
|
# 'abcdef'.hex #=> 0
|
5766
5803
|
#
|
5767
5804
|
def oct
|
5768
|
-
`var result=parseInt(this.
|
5805
|
+
`var result=parseInt(this.__value__,8)`
|
5769
5806
|
return `result.toString()=='NaN'?0:result`
|
5770
5807
|
end
|
5771
5808
|
|
@@ -5780,7 +5817,7 @@ class String
|
|
5780
5817
|
# s #=> "def"
|
5781
5818
|
#
|
5782
5819
|
def replace(str)
|
5783
|
-
`this.
|
5820
|
+
`this.__value__=str.__value__`
|
5784
5821
|
end
|
5785
5822
|
|
5786
5823
|
# call-seq:
|
@@ -5791,7 +5828,7 @@ class String
|
|
5791
5828
|
# 'abcdef'.reverse #=> 'fedcba'
|
5792
5829
|
#
|
5793
5830
|
def reverse
|
5794
|
-
`$q(this.
|
5831
|
+
`$q(this.__value__.split('').reverse().join(''))`
|
5795
5832
|
end
|
5796
5833
|
|
5797
5834
|
# call-seq:
|
@@ -5805,7 +5842,7 @@ class String
|
|
5805
5842
|
# s #=> 'fedcba'
|
5806
5843
|
#
|
5807
5844
|
def reverse!
|
5808
|
-
`this.
|
5845
|
+
`this.__value__=this.__value__.split('').reverse().join('')`
|
5809
5846
|
return self
|
5810
5847
|
end
|
5811
5848
|
|
@@ -5826,7 +5863,7 @@ class String
|
|
5826
5863
|
# 'abcdef\r\n'.rstrip #=> "abcdef"
|
5827
5864
|
#
|
5828
5865
|
def rstrip
|
5829
|
-
`$q(this.
|
5866
|
+
`$q(this.__value__.replace(/\\s*$/,''))`
|
5830
5867
|
end
|
5831
5868
|
|
5832
5869
|
# call-seq:
|
@@ -5842,9 +5879,9 @@ class String
|
|
5842
5879
|
# s #=> "abcdef"
|
5843
5880
|
#
|
5844
5881
|
def rstrip!
|
5845
|
-
`var v=this.
|
5846
|
-
`this.
|
5847
|
-
return `this.
|
5882
|
+
`var v=this.__value__`
|
5883
|
+
`this.__value__=v.replace(/\\s*$/,'')`
|
5884
|
+
return `this.__value__==v?nil:this`
|
5848
5885
|
end
|
5849
5886
|
|
5850
5887
|
# FIX: Incomplete
|
@@ -5861,7 +5898,7 @@ class String
|
|
5861
5898
|
# 'ab\ncd'.size #=> 5
|
5862
5899
|
#
|
5863
5900
|
def size
|
5864
|
-
`this.
|
5901
|
+
`this.__value__.length`
|
5865
5902
|
end
|
5866
5903
|
|
5867
5904
|
# call-seq:
|
@@ -5895,7 +5932,7 @@ class String
|
|
5895
5932
|
|
5896
5933
|
# FIX: Incomplete
|
5897
5934
|
def split(pattern = /\s+/, limit = nil)
|
5898
|
-
`var a=this.
|
5935
|
+
`var a=this.__value__.split(pattern.__value__),result=[]`
|
5899
5936
|
`for(var i=0,l=a.length;i<l;++i){result.push($q(a[i]));}`
|
5900
5937
|
return `result`
|
5901
5938
|
end
|
@@ -5913,7 +5950,7 @@ class String
|
|
5913
5950
|
# '\tabcdef\r\n'.strip #=> "abcdef"
|
5914
5951
|
#
|
5915
5952
|
def strip
|
5916
|
-
`$q(this.
|
5953
|
+
`$q(this.__value__.replace(/^\\s*|\\s*$/,''))`
|
5917
5954
|
end
|
5918
5955
|
|
5919
5956
|
# call-seq:
|
@@ -5929,9 +5966,9 @@ class String
|
|
5929
5966
|
# s #=> "abcdef"
|
5930
5967
|
#
|
5931
5968
|
def strip!
|
5932
|
-
`var v=this.
|
5933
|
-
`this.
|
5934
|
-
return `this.
|
5969
|
+
`var v=this.__value__`
|
5970
|
+
`this.__value__=v.replace(/^\\s*|\\s*$/,'')`
|
5971
|
+
return `this.__value__==v?nil:this`
|
5935
5972
|
end
|
5936
5973
|
|
5937
5974
|
# FIX: Incomplete
|
@@ -5963,7 +6000,7 @@ class String
|
|
5963
6000
|
# 'ZZZ9999'.succ #=> 'AAAA0000'
|
5964
6001
|
#
|
5965
6002
|
def succ
|
5966
|
-
`var v=this.
|
6003
|
+
`var v=this.__value__`
|
5967
6004
|
`if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
|
5968
6005
|
`if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
|
5969
6006
|
`for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
|
@@ -5979,12 +6016,12 @@ class String
|
|
5979
6016
|
# <tt>String#next</tt> for details.
|
5980
6017
|
#
|
5981
6018
|
def succ!
|
5982
|
-
`var v=this.
|
6019
|
+
`var v=this.__value__`
|
5983
6020
|
`if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}`
|
5984
6021
|
`if(/^\\d+$/.test(v)){return $q(''+(+v+1))}`
|
5985
6022
|
`for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}`
|
5986
6023
|
`if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}`
|
5987
|
-
`this.
|
6024
|
+
`this.__value__=result`
|
5988
6025
|
return self
|
5989
6026
|
end
|
5990
6027
|
|
@@ -6001,7 +6038,7 @@ class String
|
|
6001
6038
|
# 'aBc123'.swapcase #=> "AbC123"
|
6002
6039
|
#
|
6003
6040
|
def swapcase
|
6004
|
-
`$q(this.
|
6041
|
+
`$q(this.__value__.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();}))`
|
6005
6042
|
end
|
6006
6043
|
|
6007
6044
|
# call-seq:
|
@@ -6020,9 +6057,9 @@ class String
|
|
6020
6057
|
# s2 #=> "123"
|
6021
6058
|
#
|
6022
6059
|
def swapcase!
|
6023
|
-
`var v=this.
|
6024
|
-
`this.
|
6025
|
-
return `this.
|
6060
|
+
`var v=this.__value__`
|
6061
|
+
`this.__value__=v.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();})`
|
6062
|
+
return `this.__value__==v?nil:this`
|
6026
6063
|
end
|
6027
6064
|
|
6028
6065
|
# call-seq:
|
@@ -6093,7 +6130,7 @@ class String
|
|
6093
6130
|
# 'abcdef'.to_sym #=> :abcdef
|
6094
6131
|
#
|
6095
6132
|
def to_sym
|
6096
|
-
`$s(this.
|
6133
|
+
`$s(this.__value__)`
|
6097
6134
|
end
|
6098
6135
|
|
6099
6136
|
# FIX: Incomplete
|
@@ -6121,7 +6158,7 @@ class String
|
|
6121
6158
|
# 'aBCDEf'.upcase #=> "ABCDEF"
|
6122
6159
|
#
|
6123
6160
|
def upcase
|
6124
|
-
`$q(this.
|
6161
|
+
`$q(this.__value__.toUpperCase())`
|
6125
6162
|
end
|
6126
6163
|
|
6127
6164
|
# call-seq:
|
@@ -6137,9 +6174,9 @@ class String
|
|
6137
6174
|
# s #=> "ABCDEF"
|
6138
6175
|
#
|
6139
6176
|
def upcase!
|
6140
|
-
`var v=this.
|
6141
|
-
`this.
|
6142
|
-
return `v==this.
|
6177
|
+
`var v=this.__value__`
|
6178
|
+
`this.__value__=v.toUpperCase()`
|
6179
|
+
return `v==this.__value__?nil:this`
|
6143
6180
|
end
|
6144
6181
|
|
6145
6182
|
# FIX: Incomplete
|
@@ -6183,17 +6220,17 @@ class Symbol
|
|
6183
6220
|
#
|
6184
6221
|
def self.all_symbols
|
6185
6222
|
`var result=[]`
|
6186
|
-
`for(var x in c$Symbol.
|
6223
|
+
`for(var x in c$Symbol.__table__){if(c$Symbol.__table__[x].m$class()==c$Symbol){result.push(c$Symbol.__table__[x]);}}`
|
6187
6224
|
return `result`
|
6188
6225
|
end
|
6189
6226
|
|
6190
6227
|
def initialize(value) # :nodoc:
|
6191
|
-
`this.
|
6192
|
-
`c$Symbol.
|
6228
|
+
`this.__value__=value`
|
6229
|
+
`c$Symbol.__table__[value]=this`
|
6193
6230
|
end
|
6194
6231
|
|
6195
6232
|
def hash # :nodoc:
|
6196
|
-
`'s_'+this.
|
6233
|
+
`'s_'+this.__value__`
|
6197
6234
|
end
|
6198
6235
|
|
6199
6236
|
# call-seq:
|
@@ -6205,7 +6242,7 @@ class Symbol
|
|
6205
6242
|
# :foo.id2name #=> "foo"
|
6206
6243
|
#
|
6207
6244
|
def id2name
|
6208
|
-
`$q(this.
|
6245
|
+
`$q(this.__value__)`
|
6209
6246
|
end
|
6210
6247
|
|
6211
6248
|
# call-seq:
|
@@ -6240,7 +6277,7 @@ class Symbol
|
|
6240
6277
|
# :foo.to_s #=> "foo"
|
6241
6278
|
#
|
6242
6279
|
def to_s
|
6243
|
-
`$q(this.
|
6280
|
+
`$q(this.__value__)`
|
6244
6281
|
end
|
6245
6282
|
|
6246
6283
|
# call-seq:
|
@@ -6253,7 +6290,7 @@ class Symbol
|
|
6253
6290
|
return self
|
6254
6291
|
end
|
6255
6292
|
|
6256
|
-
`c$Symbol.
|
6293
|
+
`c$Symbol.__table__=new(Object)`
|
6257
6294
|
|
6258
6295
|
undef dup
|
6259
6296
|
undef clone
|
@@ -6276,7 +6313,7 @@ class Time
|
|
6276
6313
|
#
|
6277
6314
|
def self.at(seconds,milliseconds)
|
6278
6315
|
`var t=c$Time.m$new()`
|
6279
|
-
`t.
|
6316
|
+
`t.__value__=typeof(seconds)=='number'?new(Date)(seconds*1000+(milliseconds||0)):seconds.__value__`
|
6280
6317
|
return `t`
|
6281
6318
|
end
|
6282
6319
|
|
@@ -6311,7 +6348,7 @@ class Time
|
|
6311
6348
|
# t2.to_f #=> 1222222222.991
|
6312
6349
|
#
|
6313
6350
|
def initialize
|
6314
|
-
`this.
|
6351
|
+
`this.__value__=new(Date)`
|
6315
6352
|
end
|
6316
6353
|
|
6317
6354
|
# call-seq:
|
@@ -6325,7 +6362,7 @@ class Time
|
|
6325
6362
|
#
|
6326
6363
|
def +(numeric)
|
6327
6364
|
`var t=c$Time.m$new()`
|
6328
|
-
`t.
|
6365
|
+
`t.__value__=new(Date)(numeric*1000+this.__value__.valueOf())`
|
6329
6366
|
return `t`
|
6330
6367
|
end
|
6331
6368
|
|
@@ -6343,7 +6380,7 @@ class Time
|
|
6343
6380
|
# t2 - 2592000 #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
|
6344
6381
|
#
|
6345
6382
|
def -(time)
|
6346
|
-
`typeof(time)=='number'?new(Date)(this.
|
6383
|
+
`typeof(time)=='number'?new(Date)(this.__value__.valueOf()-(time*1000)):(this.__value__.valueOf()-time.__value__.valueOf())/1000`
|
6347
6384
|
end
|
6348
6385
|
|
6349
6386
|
# call-seq:
|
@@ -6360,7 +6397,7 @@ class Time
|
|
6360
6397
|
# t1 <=> t1 #=> 0
|
6361
6398
|
#
|
6362
6399
|
def <=>(time)
|
6363
|
-
`var v=this.
|
6400
|
+
`var v=this.__value__.valueOf(),ms=typeof(time)=='number'?time*1000:time.__value__.valueOf()`
|
6364
6401
|
`if(v<ms){return -1;}`
|
6365
6402
|
`if(v==ms){return 0;}`
|
6366
6403
|
`if(v>ms){return 1;}`
|
@@ -6377,7 +6414,7 @@ class Time
|
|
6377
6414
|
# t.day #=> 23
|
6378
6415
|
#
|
6379
6416
|
def day
|
6380
|
-
`this.
|
6417
|
+
`this.__value__.getDate()`
|
6381
6418
|
end
|
6382
6419
|
|
6383
6420
|
# FIX: Incomplete
|
@@ -6392,7 +6429,7 @@ class Time
|
|
6392
6429
|
#
|
6393
6430
|
def eql?(time)
|
6394
6431
|
`if(time.constructor!=c$Time){return false;}`
|
6395
|
-
`this.
|
6432
|
+
`this.__value__.valueOf()==time.__value__.valueOf()`
|
6396
6433
|
end
|
6397
6434
|
|
6398
6435
|
# FIX: Incomplete
|
@@ -6422,7 +6459,7 @@ class Time
|
|
6422
6459
|
# t.gmt_offset #=> -14400
|
6423
6460
|
#
|
6424
6461
|
def gmt_offset
|
6425
|
-
`this.
|
6462
|
+
`this.__value__.getTimezoneOffset() * -60`
|
6426
6463
|
end
|
6427
6464
|
|
6428
6465
|
# FIX: Incomplete
|
@@ -6440,11 +6477,11 @@ class Time
|
|
6440
6477
|
# t.gmtoff #=> -14400
|
6441
6478
|
#
|
6442
6479
|
def gmtoff
|
6443
|
-
`this.
|
6480
|
+
`this.__value__.getTimezoneOffset() * -60`
|
6444
6481
|
end
|
6445
6482
|
|
6446
6483
|
def hash # :nodoc:
|
6447
|
-
`'t_'+this.
|
6484
|
+
`'t_'+this.__value__.valueOf()/1000`
|
6448
6485
|
end
|
6449
6486
|
|
6450
6487
|
# call-seq:
|
@@ -6456,7 +6493,7 @@ class Time
|
|
6456
6493
|
# t.hour #=> 22
|
6457
6494
|
#
|
6458
6495
|
def hour
|
6459
|
-
`this.
|
6496
|
+
`this.__value__.getHours()`
|
6460
6497
|
end
|
6461
6498
|
|
6462
6499
|
# call-seq:
|
@@ -6489,7 +6526,7 @@ class Time
|
|
6489
6526
|
# t.mday #=> 23
|
6490
6527
|
#
|
6491
6528
|
def mday
|
6492
|
-
`this.
|
6529
|
+
`this.__value__.getDate()`
|
6493
6530
|
end
|
6494
6531
|
|
6495
6532
|
# call-seq:
|
@@ -6501,7 +6538,7 @@ class Time
|
|
6501
6538
|
# t.min #=> 10
|
6502
6539
|
#
|
6503
6540
|
def min
|
6504
|
-
`this.
|
6541
|
+
`this.__value__.getMinutes()`
|
6505
6542
|
end
|
6506
6543
|
|
6507
6544
|
# call-seq:
|
@@ -6514,7 +6551,7 @@ class Time
|
|
6514
6551
|
# t.mon #=> 9
|
6515
6552
|
#
|
6516
6553
|
def mon
|
6517
|
-
`this.
|
6554
|
+
`this.__value__.getMonth()`
|
6518
6555
|
end
|
6519
6556
|
|
6520
6557
|
# call-seq:
|
@@ -6527,7 +6564,7 @@ class Time
|
|
6527
6564
|
# t.month #=> 9
|
6528
6565
|
#
|
6529
6566
|
def month
|
6530
|
-
`this.
|
6567
|
+
`this.__value__.getMonth()`
|
6531
6568
|
end
|
6532
6569
|
|
6533
6570
|
# call-seq:
|
@@ -6539,7 +6576,7 @@ class Time
|
|
6539
6576
|
# t.sec #=> 22
|
6540
6577
|
#
|
6541
6578
|
def sec
|
6542
|
-
`this.
|
6579
|
+
`this.__value__.getSeconds()`
|
6543
6580
|
end
|
6544
6581
|
|
6545
6582
|
# FIX: Incomplete
|
@@ -6553,7 +6590,7 @@ class Time
|
|
6553
6590
|
#
|
6554
6591
|
def succ
|
6555
6592
|
`var t=c$Time.m$new()`
|
6556
|
-
`t.
|
6593
|
+
`t.__value__=new(Date)(1000+this.__value__.valueOf())`
|
6557
6594
|
return `t`
|
6558
6595
|
end
|
6559
6596
|
|
@@ -6583,7 +6620,7 @@ class Time
|
|
6583
6620
|
# t.to_f #=> 1222222222.989
|
6584
6621
|
#
|
6585
6622
|
def to_f
|
6586
|
-
`this.
|
6623
|
+
`this.__value__.valueOf()/1000`
|
6587
6624
|
end
|
6588
6625
|
|
6589
6626
|
# call-seq:
|
@@ -6595,7 +6632,7 @@ class Time
|
|
6595
6632
|
# t.to_i #=> 1222222222
|
6596
6633
|
#
|
6597
6634
|
def to_i
|
6598
|
-
`parseInt(this.
|
6635
|
+
`parseInt(this.__value__.valueOf()/1000)`
|
6599
6636
|
end
|
6600
6637
|
|
6601
6638
|
# call-seq:
|
@@ -6607,7 +6644,7 @@ class Time
|
|
6607
6644
|
# Time.now.to_s #=> "Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)"
|
6608
6645
|
#
|
6609
6646
|
def to_s
|
6610
|
-
`$q(''+this.
|
6647
|
+
`$q(''+this.__value__)`
|
6611
6648
|
end
|
6612
6649
|
|
6613
6650
|
# call-seq:
|
@@ -6619,7 +6656,7 @@ class Time
|
|
6619
6656
|
# t.tv_sec #=> 1222222222
|
6620
6657
|
#
|
6621
6658
|
def tv_sec
|
6622
|
-
`parseInt(this.
|
6659
|
+
`parseInt(this.__value__.valueOf()/1000)`
|
6623
6660
|
end
|
6624
6661
|
|
6625
6662
|
# call-seq:
|
@@ -6633,7 +6670,7 @@ class Time
|
|
6633
6670
|
# t.tv_usec #=> 989000
|
6634
6671
|
#
|
6635
6672
|
def tv_usec
|
6636
|
-
`parseInt(this.
|
6673
|
+
`parseInt(this.__value__.valueOf()/1000)`
|
6637
6674
|
end
|
6638
6675
|
|
6639
6676
|
# call-seq:
|
@@ -6647,7 +6684,7 @@ class Time
|
|
6647
6684
|
# t.usec #=> 989000
|
6648
6685
|
#
|
6649
6686
|
def usec
|
6650
|
-
`var v = this.
|
6687
|
+
`var v = this.__value__.valueOf()`
|
6651
6688
|
`(v*1000)-parseInt(v/1000)*1000000`
|
6652
6689
|
end
|
6653
6690
|
|
@@ -6670,7 +6707,7 @@ class Time
|
|
6670
6707
|
# t.utc_offset #=> -14400
|
6671
6708
|
#
|
6672
6709
|
def utc_offset
|
6673
|
-
`this.
|
6710
|
+
`this.__value__.getTimezoneOffset() * -60`
|
6674
6711
|
end
|
6675
6712
|
|
6676
6713
|
# call-seq:
|
@@ -6682,7 +6719,7 @@ class Time
|
|
6682
6719
|
# t.wday #=> 2
|
6683
6720
|
#
|
6684
6721
|
def wday
|
6685
|
-
`this.
|
6722
|
+
`this.__value__.getDay()`
|
6686
6723
|
end
|
6687
6724
|
|
6688
6725
|
# call-seq:
|
@@ -6707,7 +6744,7 @@ class Time
|
|
6707
6744
|
# t.year #=> 2008
|
6708
6745
|
#
|
6709
6746
|
def year
|
6710
|
-
`this.
|
6747
|
+
`this.__value__.getFullYear()`
|
6711
6748
|
end
|
6712
6749
|
|
6713
6750
|
# FIX: Incomplete
|
@@ -6753,6 +6790,22 @@ class TrueClass
|
|
6753
6790
|
`this.valueOf()?!$T(object):$T(object)`
|
6754
6791
|
end
|
6755
6792
|
|
6793
|
+
def ==(obj) # :nodoc:
|
6794
|
+
`obj.valueOf&&obj.valueOf()===this.valueOf()`
|
6795
|
+
end
|
6796
|
+
|
6797
|
+
def ===(obj) # :nodoc:
|
6798
|
+
`obj.valueOf&&obj.valueOf()===this.valueOf()`
|
6799
|
+
end
|
6800
|
+
|
6801
|
+
def eql?(obj) # :nodoc:
|
6802
|
+
`obj.valueOf&&obj.valueOf()===this.valueOf()`
|
6803
|
+
end
|
6804
|
+
|
6805
|
+
def equal?(obj) # :nodoc:
|
6806
|
+
`obj.valueOf&&obj.valueOf()===this.valueOf()`
|
6807
|
+
end
|
6808
|
+
|
6756
6809
|
def hash # :nodoc:
|
6757
6810
|
`'b_'+this.valueOf()`
|
6758
6811
|
end
|
@@ -6775,10 +6828,10 @@ end
|
|
6775
6828
|
`
|
6776
6829
|
|
6777
6830
|
c$NilClass.prototype.toString=function(){return 'nil';};
|
6778
|
-
c$Range.prototype.toString=function(){return ''+this.
|
6779
|
-
c$Regexp.prototype.toString=function(){return '/'+this.
|
6780
|
-
c$String.prototype.toString=function(){return this.
|
6781
|
-
c$Symbol.prototype.toString=function(){var v=this.
|
6782
|
-
c$Time.prototype.toString=function(){return ''+this.
|
6831
|
+
c$Range.prototype.toString=function(){return ''+this.__start__+(this.__exclusive__?'...':'..')+this.__end__;};
|
6832
|
+
c$Regexp.prototype.toString=function(){return '/'+this.__source__+'/'+(/s/.test(this.__options__)?'m':'')+(/i/.test(this.__options__)?'i':'')+(/x/.test(this.__options__)?'x':'');};
|
6833
|
+
c$String.prototype.toString=function(){return this.__value__;};
|
6834
|
+
c$Symbol.prototype.toString=function(){var v=this.__value__,str=/\\s/.test(v)?'"'+v+'"':v;return ':'+str ;};
|
6835
|
+
c$Time.prototype.toString=function(){return ''+this.__value__;};
|
6783
6836
|
|
6784
6837
|
`
|