opal 0.3.20 → 0.3.21
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/.gitignore +2 -7
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +8 -2
- data/LICENSE +2 -3
- data/README.md +106 -239
- data/Rakefile +58 -16
- data/bin/opal +1 -0
- data/core/array.rb +180 -160
- data/core/basic_object.rb +8 -4
- data/core/boolean.rb +6 -6
- data/core/class.rb +9 -15
- data/core/dir.rb +89 -0
- data/core/enumerable.rb +83 -86
- data/core/error.rb +9 -4
- data/core/file.rb +85 -0
- data/core/hash.rb +67 -67
- data/core/kernel.rb +38 -42
- data/core/module.rb +57 -54
- data/core/numeric.rb +41 -41
- data/core/proc.rb +1 -5
- data/core/range.rb +11 -11
- data/core/regexp.rb +27 -22
- data/core/runtime.js +152 -221
- data/core/string.rb +86 -73
- data/core/time.rb +22 -18
- data/docs/post.html +9 -0
- data/docs/pre.html +32 -0
- data/lib/opal.rb +43 -3
- data/lib/opal/builder.rb +9 -26
- data/lib/opal/grammar.rb +1 -1
- data/lib/opal/grammar.y +1 -1
- data/lib/opal/lexer.rb +21 -15
- data/lib/opal/parser.rb +100 -111
- data/lib/opal/rake_task.rb +66 -0
- data/lib/opal/scope.rb +13 -5
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +2 -0
- data/spec/browser_spec.rb +28 -0
- data/spec/builder/lib_name_for_spec.rb +1 -6
- data/spec/grammar/alias_spec.rb +1 -1
- data/spec/grammar/and_spec.rb +1 -1
- data/spec/grammar/array_spec.rb +1 -1
- data/spec/grammar/attrasgn_spec.rb +1 -1
- data/spec/grammar/begin_spec.rb +1 -1
- data/spec/grammar/block_spec.rb +1 -1
- data/spec/grammar/break_spec.rb +1 -1
- data/spec/grammar/call_spec.rb +1 -1
- data/spec/grammar/class_spec.rb +1 -1
- data/spec/grammar/const_spec.rb +1 -1
- data/spec/grammar/cvar_spec.rb +1 -1
- data/spec/grammar/def_spec.rb +1 -1
- data/spec/grammar/false_spec.rb +1 -1
- data/spec/grammar/file_spec.rb +1 -1
- data/spec/grammar/gvar_spec.rb +1 -1
- data/spec/grammar/hash_spec.rb +1 -1
- data/spec/grammar/iasgn_spec.rb +1 -1
- data/spec/grammar/if_spec.rb +1 -1
- data/spec/grammar/iter_spec.rb +1 -1
- data/spec/grammar/ivar_spec.rb +1 -1
- data/spec/grammar/lambda_spec.rb +1 -1
- data/spec/grammar/lasgn_spec.rb +1 -1
- data/spec/grammar/line_spec.rb +1 -1
- data/spec/grammar/lvar_spec.rb +1 -1
- data/spec/grammar/masgn_spec.rb +1 -1
- data/spec/grammar/module_spec.rb +1 -1
- data/spec/grammar/nil_spec.rb +1 -1
- data/spec/grammar/not_spec.rb +1 -1
- data/spec/grammar/op_asgn1_spec.rb +1 -1
- data/spec/grammar/op_asgn2_spec.rb +1 -1
- data/spec/grammar/or_spec.rb +1 -1
- data/spec/grammar/return_spec.rb +1 -1
- data/spec/grammar/sclass_spec.rb +1 -1
- data/spec/grammar/self_spec.rb +1 -1
- data/spec/grammar/str_spec.rb +1 -1
- data/spec/grammar/super_spec.rb +1 -1
- data/spec/grammar/true_spec.rb +1 -1
- data/spec/grammar/undef_spec.rb +1 -1
- data/spec/grammar/unless_spec.rb +1 -1
- data/spec/grammar/while_spec.rb +1 -1
- data/spec/grammar/xstr_spec.rb +1 -1
- data/spec/grammar/yield_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -1
- data/test/core/array/minus_spec.rb +13 -0
- data/test/core/enumerable/drop_while_spec.rb +0 -5
- data/test/core/range/case_compare_spec.rb +0 -1
- data/test/index.html +1 -1
- data/test/index.min.html +12 -0
- data/test/language/alias_spec.rb +0 -4
- data/test/language/fixtures/next.rb +62 -0
- data/test/language/metaclass_spec.rb +4 -4
- data/test/language/next_spec.rb +0 -63
- data/test/language/send_spec.rb +0 -5
- data/test/language/singleton_class_spec.rb +4 -0
- data/test/opal/array/subclassing_spec.rb +1 -1
- data/test/opal/class/bridge_class_spec.rb +2 -2
- data/test/opal/runtime/class_hierarchy_spec.rb +1 -2
- data/test/opal/runtime/method_missing_spec.rb +17 -0
- data/test/spec_helper.rb +4 -1
- metadata +32 -28
- data/docs/CNAME +0 -1
- data/docs/Rakefile +0 -55
- data/docs/css/styles.css +0 -50
- data/docs/css/syntax.css +0 -63
- data/docs/layout/post.html +0 -3
- data/docs/layout/pre.html +0 -11
- data/examples/dependencies/.gitignore +0 -1
- data/examples/dependencies/Gemfile +0 -6
- data/examples/dependencies/README.md +0 -41
- data/examples/dependencies/Rakefile +0 -10
- data/examples/dependencies/app.rb +0 -19
- data/examples/dependencies/build/.gitkeep +0 -0
- data/examples/dependencies/index.html +0 -13
- data/examples/hello_world/.gitignore +0 -1
- data/examples/hello_world/Gemfile +0 -3
- data/examples/hello_world/README.md +0 -27
- data/examples/hello_world/Rakefile +0 -23
- data/examples/hello_world/app.rb +0 -7
- data/examples/hello_world/index.html +0 -12
- data/lib/opal/builder_task.rb +0 -91
- data/spec/builder/build_order_spec.rb +0 -20
- data/test/opal/runtime/_methods_spec.rb +0 -48
data/core/string.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
class String < `String`
|
|
2
|
-
|
|
3
|
-
String_prototype._isString = true;
|
|
4
|
-
}
|
|
2
|
+
`String.prototype._isString = true`
|
|
5
3
|
|
|
6
4
|
include Comparable
|
|
7
5
|
|
|
@@ -12,7 +10,12 @@ class String < `String`
|
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def self.new(str = '')
|
|
15
|
-
|
|
13
|
+
%x{
|
|
14
|
+
var s = new String(#{str.to_s});
|
|
15
|
+
s.$m = #{self}.$m_tbl;
|
|
16
|
+
s.$k = #{self};
|
|
17
|
+
return s;
|
|
18
|
+
}
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def %(data)
|
|
@@ -26,7 +29,7 @@ class String < `String`
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
var result = '',
|
|
29
|
-
pattern =
|
|
32
|
+
pattern = #{self}.valueOf();
|
|
30
33
|
|
|
31
34
|
while (count > 0) {
|
|
32
35
|
if (count & 1) {
|
|
@@ -41,7 +44,7 @@ class String < `String`
|
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
def +(other)
|
|
44
|
-
|
|
47
|
+
`#{self}.toString() + other`
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
def <=>(other)
|
|
@@ -50,28 +53,28 @@ class String < `String`
|
|
|
50
53
|
return nil;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
return
|
|
56
|
+
return #{self} > other ? 1 : (#{self} < other ? -1 : 0);
|
|
54
57
|
}
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
def <(other)
|
|
58
|
-
|
|
61
|
+
`#{self} < other`
|
|
59
62
|
end
|
|
60
63
|
|
|
61
64
|
def <=(other)
|
|
62
|
-
|
|
65
|
+
`#{self} <= other`
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
def >(other)
|
|
66
|
-
|
|
69
|
+
`#{self} > other`
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
def >=(other)
|
|
70
|
-
|
|
73
|
+
`#{self} >= other`
|
|
71
74
|
end
|
|
72
75
|
|
|
73
76
|
def ==(other)
|
|
74
|
-
|
|
77
|
+
`#{self} == other`
|
|
75
78
|
end
|
|
76
79
|
|
|
77
80
|
alias === ==
|
|
@@ -91,30 +94,30 @@ class String < `String`
|
|
|
91
94
|
%x{
|
|
92
95
|
if (length == null) {
|
|
93
96
|
if (index < 0) {
|
|
94
|
-
index +=
|
|
97
|
+
index += #{self}.length;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
if (index >=
|
|
100
|
+
if (index >= #{self}.length || index < 0) {
|
|
98
101
|
return nil;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
return
|
|
104
|
+
return #{self}.substr(index, 1);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
if (index < 0) {
|
|
105
|
-
index +=
|
|
108
|
+
index += #{self}.length + 1;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
if (index >
|
|
111
|
+
if (index > #{self}.length || index < 0) {
|
|
109
112
|
return nil;
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
return
|
|
115
|
+
return #{self}.substr(index, length);
|
|
113
116
|
}
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
def capitalize
|
|
117
|
-
|
|
120
|
+
`#{self}.charAt(0).toUpperCase() + #{self}.substr(1).toLowerCase()`
|
|
118
121
|
end
|
|
119
122
|
|
|
120
123
|
def casecmp(other)
|
|
@@ -123,7 +126,7 @@ class String < `String`
|
|
|
123
126
|
return other;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
var a =
|
|
129
|
+
var a = #{self}.toLowerCase(),
|
|
127
130
|
b = other.toLowerCase();
|
|
128
131
|
|
|
129
132
|
return a > b ? 1 : (a < b ? -1 : 0);
|
|
@@ -134,8 +137,8 @@ class String < `String`
|
|
|
134
137
|
return enum_for :chars unless block_given?
|
|
135
138
|
|
|
136
139
|
%x{
|
|
137
|
-
for (var i = 0, length =
|
|
138
|
-
#{yield
|
|
140
|
+
for (var i = 0, length = #{self}.length; i < length; i++) {
|
|
141
|
+
#{yield `#{self}.charAt(i)`}
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
end
|
|
@@ -143,24 +146,26 @@ class String < `String`
|
|
|
143
146
|
def chomp(separator = $/)
|
|
144
147
|
%x{
|
|
145
148
|
if (separator === "\\n") {
|
|
146
|
-
return
|
|
149
|
+
return #{self}.replace(/(\\n|\\r|\\r\\n)$/, '');
|
|
147
150
|
}
|
|
148
151
|
else if (separator === "") {
|
|
149
|
-
return
|
|
152
|
+
return #{self}.replace(/(\\n|\\r\\n)+$/, '');
|
|
150
153
|
}
|
|
151
|
-
return
|
|
154
|
+
return #{self}.replace(new RegExp(separator + '$'), '');
|
|
152
155
|
}
|
|
153
156
|
end
|
|
154
157
|
|
|
155
158
|
def chop
|
|
156
|
-
|
|
159
|
+
`#{self}.substr(0, #{self}.length - 1)`
|
|
157
160
|
end
|
|
158
161
|
|
|
159
162
|
def chr
|
|
160
|
-
|
|
163
|
+
`#{self}.charAt(0)`
|
|
161
164
|
end
|
|
162
165
|
|
|
163
|
-
|
|
166
|
+
def downcase
|
|
167
|
+
`#{self}.toLowerCase()`
|
|
168
|
+
end
|
|
164
169
|
|
|
165
170
|
alias each_char chars
|
|
166
171
|
|
|
@@ -168,7 +173,7 @@ class String < `String`
|
|
|
168
173
|
return enum_for :each_line, separator unless block_given?
|
|
169
174
|
|
|
170
175
|
%x{
|
|
171
|
-
var splitted =
|
|
176
|
+
var splitted = #{self}.split(separator);
|
|
172
177
|
|
|
173
178
|
for (var i = 0, length = splitted.length; i < length; i++) {
|
|
174
179
|
#{yield `splitted[i] + separator`}
|
|
@@ -177,7 +182,7 @@ class String < `String`
|
|
|
177
182
|
end
|
|
178
183
|
|
|
179
184
|
def empty?
|
|
180
|
-
|
|
185
|
+
`#{self}.length === 0`
|
|
181
186
|
end
|
|
182
187
|
|
|
183
188
|
def end_with?(*suffixes)
|
|
@@ -185,7 +190,7 @@ class String < `String`
|
|
|
185
190
|
for (var i = 0, length = suffixes.length; i < length; i++) {
|
|
186
191
|
var suffix = suffixes[i];
|
|
187
192
|
|
|
188
|
-
if (
|
|
193
|
+
if (#{self}.lastIndexOf(suffix) === #{self}.length - suffix.length) {
|
|
189
194
|
return true;
|
|
190
195
|
}
|
|
191
196
|
}
|
|
@@ -197,10 +202,12 @@ class String < `String`
|
|
|
197
202
|
alias eql? ==
|
|
198
203
|
|
|
199
204
|
def equal?(val)
|
|
200
|
-
|
|
205
|
+
`#{self}.toString() === val.toString()`
|
|
201
206
|
end
|
|
202
207
|
|
|
203
|
-
|
|
208
|
+
def getbyte(idx)
|
|
209
|
+
`#{self}.charCodeAt(idx)`
|
|
210
|
+
end
|
|
204
211
|
|
|
205
212
|
def gsub(pattern, replace, &block)
|
|
206
213
|
return enum_for :gsub, pattern, replace if !block && `pattern == null`
|
|
@@ -218,14 +225,16 @@ class String < `String`
|
|
|
218
225
|
}
|
|
219
226
|
end
|
|
220
227
|
|
|
221
|
-
|
|
228
|
+
def hash
|
|
229
|
+
`#{self}.toString()`
|
|
230
|
+
end
|
|
222
231
|
|
|
223
232
|
def hex
|
|
224
233
|
to_i 16
|
|
225
234
|
end
|
|
226
235
|
|
|
227
236
|
def include?(other)
|
|
228
|
-
|
|
237
|
+
`#{self}.indexOf(other) !== -1`
|
|
229
238
|
end
|
|
230
239
|
|
|
231
240
|
def index(what, offset)
|
|
@@ -238,14 +247,14 @@ class String < `String`
|
|
|
238
247
|
|
|
239
248
|
if (offset != null) {
|
|
240
249
|
if (offset < 0) {
|
|
241
|
-
offset =
|
|
250
|
+
offset = #{self}.length - offset;
|
|
242
251
|
}
|
|
243
252
|
|
|
244
253
|
if (#{what.is_a?(Regexp)}) {
|
|
245
|
-
result = #{what =~
|
|
254
|
+
result = #{what =~ `#{self}.substr(offset)` || -1}
|
|
246
255
|
}
|
|
247
256
|
else {
|
|
248
|
-
result =
|
|
257
|
+
result = #{self}.substr(offset).indexOf(substr);
|
|
249
258
|
}
|
|
250
259
|
|
|
251
260
|
if (result !== -1) {
|
|
@@ -257,7 +266,7 @@ class String < `String`
|
|
|
257
266
|
result = #{(what =~ self) || -1}
|
|
258
267
|
}
|
|
259
268
|
else {
|
|
260
|
-
result =
|
|
269
|
+
result = #{self}.indexOf(substr);
|
|
261
270
|
}
|
|
262
271
|
}
|
|
263
272
|
|
|
@@ -280,12 +289,12 @@ class String < `String`
|
|
|
280
289
|
|
|
281
290
|
escapable.lastIndex = 0;
|
|
282
291
|
|
|
283
|
-
return escapable.test(
|
|
292
|
+
return escapable.test(#{self}) ? '"' + #{self}.replace(escapable, function(a) {
|
|
284
293
|
var c = meta[a];
|
|
285
294
|
|
|
286
295
|
return typeof c === 'string' ? c :
|
|
287
296
|
'\\\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
|
288
|
-
}) + '"' : '"' +
|
|
297
|
+
}) + '"' : '"' + #{self} + '"';
|
|
289
298
|
}
|
|
290
299
|
end
|
|
291
300
|
|
|
@@ -296,7 +305,7 @@ class String < `String`
|
|
|
296
305
|
alias lines each_line
|
|
297
306
|
|
|
298
307
|
def length
|
|
299
|
-
|
|
308
|
+
`#{self}.length`
|
|
300
309
|
end
|
|
301
310
|
|
|
302
311
|
def ljust(integer, padstr = ' ')
|
|
@@ -304,7 +313,7 @@ class String < `String`
|
|
|
304
313
|
end
|
|
305
314
|
|
|
306
315
|
def lstrip
|
|
307
|
-
|
|
316
|
+
`#{self}.replace(/^\\s*/, '')`
|
|
308
317
|
end
|
|
309
318
|
|
|
310
319
|
def match(pattern, pos, &block)
|
|
@@ -313,36 +322,36 @@ class String < `String`
|
|
|
313
322
|
|
|
314
323
|
def next
|
|
315
324
|
%x{
|
|
316
|
-
if (
|
|
325
|
+
if (#{self}.length === 0) {
|
|
317
326
|
return "";
|
|
318
327
|
}
|
|
319
328
|
|
|
320
|
-
var initial =
|
|
321
|
-
var last = String.fromCharCode(
|
|
329
|
+
var initial = #{self}.substr(0, #{self}.length - 1);
|
|
330
|
+
var last = String.fromCharCode(#{self}.charCodeAt(#{self}.length - 1) + 1);
|
|
322
331
|
|
|
323
332
|
return initial + last;
|
|
324
333
|
}
|
|
325
334
|
end
|
|
326
335
|
|
|
327
336
|
def ord
|
|
328
|
-
|
|
337
|
+
`#{self}.charCodeAt(0)`
|
|
329
338
|
end
|
|
330
339
|
|
|
331
340
|
def partition(str)
|
|
332
341
|
%x{
|
|
333
|
-
var result =
|
|
334
|
-
var splitter = (result[0].length ===
|
|
342
|
+
var result = #{self}.split(str);
|
|
343
|
+
var splitter = (result[0].length === #{self}.length ? "" : str);
|
|
335
344
|
|
|
336
345
|
return [result[0], splitter, result.slice(1).join(str.toString())];
|
|
337
346
|
}
|
|
338
347
|
end
|
|
339
348
|
|
|
340
349
|
def reverse
|
|
341
|
-
|
|
350
|
+
`#{self}.split('').reverse().join('')`
|
|
342
351
|
end
|
|
343
352
|
|
|
344
353
|
def rstrip
|
|
345
|
-
|
|
354
|
+
`#{self}.replace(/\\s*$/, '')`
|
|
346
355
|
end
|
|
347
356
|
|
|
348
357
|
alias size length
|
|
@@ -350,13 +359,13 @@ class String < `String`
|
|
|
350
359
|
alias slice []
|
|
351
360
|
|
|
352
361
|
def split(pattern = $; || ' ', limit = undefined)
|
|
353
|
-
|
|
362
|
+
`#{self}.split(pattern, limit)`
|
|
354
363
|
end
|
|
355
364
|
|
|
356
365
|
def start_with?(*prefixes)
|
|
357
366
|
%x{
|
|
358
367
|
for (var i = 0, length = prefixes.length; i < length; i++) {
|
|
359
|
-
if (
|
|
368
|
+
if (#{self}.indexOf(prefixes[i]) === 0) {
|
|
360
369
|
return true;
|
|
361
370
|
}
|
|
362
371
|
}
|
|
@@ -366,22 +375,22 @@ class String < `String`
|
|
|
366
375
|
end
|
|
367
376
|
|
|
368
377
|
def strip
|
|
369
|
-
|
|
378
|
+
`#{self}.replace(/^\\s*/, '').replace(/\\s*$/, '')`
|
|
370
379
|
end
|
|
371
380
|
|
|
372
381
|
def sub(pattern, replace, &block)
|
|
373
382
|
%x{
|
|
374
383
|
if (typeof(replace) === 'string') {
|
|
375
|
-
return
|
|
384
|
+
return #{self}.replace(pattern, replace);
|
|
376
385
|
}
|
|
377
386
|
if (block !== nil) {
|
|
378
|
-
return
|
|
379
|
-
return block
|
|
387
|
+
return #{self}.replace(pattern, function(str) {
|
|
388
|
+
return block(__context, str);
|
|
380
389
|
});
|
|
381
390
|
}
|
|
382
391
|
else if (replace != null) {
|
|
383
392
|
if (#{replace.is_a?(Hash)}) {
|
|
384
|
-
return
|
|
393
|
+
return #{self}.replace(pattern, function(str) {
|
|
385
394
|
var value = #{replace[str]};
|
|
386
395
|
|
|
387
396
|
return (value == null) ? nil : #{value.to_s};
|
|
@@ -394,11 +403,11 @@ class String < `String`
|
|
|
394
403
|
#{raise TypeError, "can't convert #{replace.class} into String"};
|
|
395
404
|
}
|
|
396
405
|
|
|
397
|
-
return
|
|
406
|
+
return #{self}.replace(pattern, replace);
|
|
398
407
|
}
|
|
399
408
|
}
|
|
400
409
|
else {
|
|
401
|
-
return
|
|
410
|
+
return #{self}.replace(pattern, replace.toString());
|
|
402
411
|
}
|
|
403
412
|
}
|
|
404
413
|
end
|
|
@@ -409,8 +418,8 @@ class String < `String`
|
|
|
409
418
|
%x{
|
|
410
419
|
var result = 0;
|
|
411
420
|
|
|
412
|
-
for (var i = 0, length =
|
|
413
|
-
result += (
|
|
421
|
+
for (var i = 0, length = #{self}.length; i < length; i++) {
|
|
422
|
+
result += (#{self}.charCodeAt(i) % ((1 << n) - 1));
|
|
414
423
|
}
|
|
415
424
|
|
|
416
425
|
return result;
|
|
@@ -419,31 +428,31 @@ class String < `String`
|
|
|
419
428
|
|
|
420
429
|
def swapcase
|
|
421
430
|
%x{
|
|
422
|
-
var str =
|
|
431
|
+
var str = #{self}.replace(/([a-z]+)|([A-Z]+)/g, function($0,$1,$2) {
|
|
423
432
|
return $1 ? $0.toUpperCase() : $0.toLowerCase();
|
|
424
433
|
});
|
|
425
434
|
|
|
426
|
-
if (
|
|
435
|
+
if (#{self}.$k === String) {
|
|
427
436
|
return str;
|
|
428
437
|
}
|
|
429
438
|
|
|
430
|
-
return
|
|
439
|
+
return #{self.class.new `str`};
|
|
431
440
|
}
|
|
432
441
|
end
|
|
433
442
|
|
|
434
443
|
def to_a
|
|
435
444
|
%x{
|
|
436
|
-
if (
|
|
445
|
+
if (#{self}.length === 0) {
|
|
437
446
|
return [];
|
|
438
447
|
}
|
|
439
448
|
|
|
440
|
-
return [
|
|
449
|
+
return [#{self}];
|
|
441
450
|
}
|
|
442
451
|
end
|
|
443
452
|
|
|
444
453
|
def to_f
|
|
445
454
|
%x{
|
|
446
|
-
var result = parseFloat(
|
|
455
|
+
var result = parseFloat(#{self});
|
|
447
456
|
|
|
448
457
|
return isNaN(result) ? 0 : result;
|
|
449
458
|
}
|
|
@@ -451,7 +460,7 @@ class String < `String`
|
|
|
451
460
|
|
|
452
461
|
def to_i(base = 10)
|
|
453
462
|
%x{
|
|
454
|
-
var result = parseInt(
|
|
463
|
+
var result = parseInt(#{self}, base);
|
|
455
464
|
|
|
456
465
|
if (isNaN(result)) {
|
|
457
466
|
return 0;
|
|
@@ -465,19 +474,23 @@ class String < `String`
|
|
|
465
474
|
|
|
466
475
|
def to_proc
|
|
467
476
|
%x{
|
|
468
|
-
var
|
|
477
|
+
var name = #{self};
|
|
469
478
|
|
|
470
|
-
return function(arg) { return arg[
|
|
479
|
+
return function(s, arg) { return arg.$m[name](arg); };
|
|
471
480
|
}
|
|
472
481
|
end
|
|
473
482
|
|
|
474
|
-
|
|
483
|
+
def to_s
|
|
484
|
+
`#{self}.toString()`
|
|
485
|
+
end
|
|
475
486
|
|
|
476
487
|
alias to_str to_s
|
|
477
488
|
|
|
478
489
|
alias to_sym intern
|
|
479
490
|
|
|
480
|
-
|
|
491
|
+
def upcase
|
|
492
|
+
`#{self}.toUpperCase()`
|
|
493
|
+
end
|
|
481
494
|
end
|
|
482
495
|
|
|
483
496
|
Symbol = String
|