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/kernel.rb
CHANGED
|
@@ -4,11 +4,11 @@ module Kernel
|
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def ==(other)
|
|
7
|
-
|
|
7
|
+
`#{self} === other`
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def ===(other)
|
|
11
|
-
|
|
11
|
+
`#{self} == other`
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def Array(object)
|
|
@@ -34,7 +34,7 @@ module Kernel
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def class
|
|
37
|
-
`return
|
|
37
|
+
`return #{self}.$k`
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def define_singleton_method(name, &body)
|
|
@@ -43,33 +43,33 @@ module Kernel
|
|
|
43
43
|
no_block_given();
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
body._jsid = jsid;
|
|
48
|
-
body._sup = this[jsid]
|
|
46
|
+
#{ self.singleton_class };
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
body._jsid = name;
|
|
49
|
+
body._sup = #{self}.$m[name]
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
#{self}.$m[name] = body;
|
|
52
|
+
|
|
53
|
+
return #{self};
|
|
54
54
|
}
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def equal?(other)
|
|
58
|
-
|
|
58
|
+
`#{self} === other`
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def extend(*mods)
|
|
62
62
|
%x{
|
|
63
63
|
for (var i = 0, length = mods.length; i < length; i++) {
|
|
64
|
-
|
|
64
|
+
#{ self.singleton_class.include `mods[i]` };
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return
|
|
67
|
+
return #{self};
|
|
68
68
|
}
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def hash
|
|
72
|
-
|
|
72
|
+
`#{self}._id`
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
def inspect
|
|
@@ -77,30 +77,30 @@ module Kernel
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def instance_of?(klass)
|
|
80
|
-
|
|
80
|
+
`#{self}.$k === klass`
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def instance_variable_defined?(name)
|
|
84
|
-
`__hasOwn.call(
|
|
84
|
+
`__hasOwn.call(#{self}, name.substr(1))`
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def instance_variable_get(name)
|
|
88
88
|
%x{
|
|
89
|
-
var ivar =
|
|
89
|
+
var ivar = #{self}[name.substr(1)];
|
|
90
90
|
|
|
91
91
|
return ivar == null ? nil : ivar;
|
|
92
92
|
}
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def instance_variable_set(name, value)
|
|
96
|
-
|
|
96
|
+
`#{self}[name.substr(1)] = value`
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def instance_variables
|
|
100
100
|
%x{
|
|
101
101
|
var result = [];
|
|
102
102
|
|
|
103
|
-
for (var name in
|
|
103
|
+
for (var name in #{self}) {
|
|
104
104
|
result.push(name);
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -110,14 +110,14 @@ module Kernel
|
|
|
110
110
|
|
|
111
111
|
def is_a?(klass)
|
|
112
112
|
%x{
|
|
113
|
-
var search =
|
|
113
|
+
var search = #{self}.$k;
|
|
114
114
|
|
|
115
115
|
while (search) {
|
|
116
116
|
if (search === klass) {
|
|
117
117
|
return true;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
search = search
|
|
120
|
+
search = search.$s;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
return false;
|
|
@@ -133,15 +133,11 @@ module Kernel
|
|
|
133
133
|
def loop(&block)
|
|
134
134
|
return enum_for :loop unless block_given?
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return __breaker.$v;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
136
|
+
`while (true) {`
|
|
137
|
+
yield
|
|
138
|
+
`}`
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
}
|
|
140
|
+
self
|
|
145
141
|
end
|
|
146
142
|
|
|
147
143
|
def nil?
|
|
@@ -149,7 +145,7 @@ module Kernel
|
|
|
149
145
|
end
|
|
150
146
|
|
|
151
147
|
def object_id
|
|
152
|
-
|
|
148
|
+
`#{self}._id || (#{self}._id = unique_id++)`
|
|
153
149
|
end
|
|
154
150
|
|
|
155
151
|
def proc(&block)
|
|
@@ -191,30 +187,30 @@ module Kernel
|
|
|
191
187
|
end
|
|
192
188
|
|
|
193
189
|
def respond_to?(name)
|
|
194
|
-
|
|
190
|
+
`!!#{self}.$m[name]`
|
|
195
191
|
end
|
|
196
192
|
|
|
197
193
|
def singleton_class
|
|
198
194
|
%x{
|
|
199
|
-
if (
|
|
200
|
-
return
|
|
195
|
+
if (!#{self}._isObject) {
|
|
196
|
+
return #{self}.$k;
|
|
201
197
|
}
|
|
202
198
|
|
|
203
|
-
if (
|
|
204
|
-
return
|
|
199
|
+
if (#{self}._singleton) {
|
|
200
|
+
return #{self}._singleton;
|
|
205
201
|
}
|
|
202
|
+
|
|
206
203
|
else {
|
|
207
|
-
var orig_class =
|
|
204
|
+
var orig_class = #{self}.$k,
|
|
208
205
|
class_id = "#<Class:#<" + orig_class._name + ":" + orig_class._id + ">>";
|
|
209
206
|
|
|
210
|
-
function
|
|
211
|
-
var meta = boot_class(orig_class,
|
|
207
|
+
function Singleton() {};
|
|
208
|
+
var meta = boot_class(orig_class, Singleton);
|
|
212
209
|
meta._name = class_id;
|
|
213
210
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
meta._klass = orig_class._real;
|
|
211
|
+
#{self}.$m = meta.$m_tbl;
|
|
212
|
+
#{self}._singleton = meta;
|
|
213
|
+
meta.$k = orig_class.$k;
|
|
218
214
|
|
|
219
215
|
return meta;
|
|
220
216
|
}
|
|
@@ -237,7 +233,7 @@ module Kernel
|
|
|
237
233
|
end
|
|
238
234
|
|
|
239
235
|
def to_s
|
|
240
|
-
`return "#<" +
|
|
236
|
+
`return "#<" + #{self}.$k._name + ":" + #{self}._id + ">";`
|
|
241
237
|
end
|
|
242
238
|
|
|
243
239
|
def enum_for (method = :each, *args)
|
data/core/module.rb
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
class Module
|
|
2
|
+
def ===(object)
|
|
3
|
+
%x{
|
|
4
|
+
if (object == null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
var search = object.$k;
|
|
9
|
+
|
|
10
|
+
while (search) {
|
|
11
|
+
if (search === #{self}) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
search = search._super;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
2
22
|
def alias_method(newname, oldname)
|
|
3
|
-
|
|
23
|
+
`#{self}.$m_tbl[newname] = #{self}.$m_tbl[oldname]`
|
|
4
24
|
self
|
|
5
25
|
end
|
|
6
26
|
|
|
7
27
|
def ancestors
|
|
8
28
|
%x{
|
|
9
|
-
var parent =
|
|
29
|
+
var parent = #{self},
|
|
10
30
|
result = [];
|
|
11
31
|
|
|
12
32
|
while (parent) {
|
|
13
|
-
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
else if (parent._isIClass)
|
|
17
|
-
result.push(parent._klass);
|
|
18
|
-
else {
|
|
19
|
-
result.push(parent);
|
|
20
|
-
}
|
|
21
|
-
|
|
33
|
+
result.push(parent);
|
|
22
34
|
parent = parent._super;
|
|
23
35
|
}
|
|
24
36
|
|
|
@@ -28,7 +40,7 @@ class Module
|
|
|
28
40
|
|
|
29
41
|
def append_features(klass)
|
|
30
42
|
%x{
|
|
31
|
-
var module =
|
|
43
|
+
var module = #{self};
|
|
32
44
|
|
|
33
45
|
if (!klass.$included_modules) {
|
|
34
46
|
klass.$included_modules = [];
|
|
@@ -48,17 +60,15 @@ class Module
|
|
|
48
60
|
|
|
49
61
|
module.$included_in.push(klass);
|
|
50
62
|
|
|
51
|
-
var donator = module
|
|
52
|
-
|
|
53
|
-
methods = module._methods;
|
|
63
|
+
var donator = module.$m_tbl,
|
|
64
|
+
target = klass.$m_tbl;
|
|
54
65
|
|
|
55
|
-
for (var
|
|
56
|
-
|
|
57
|
-
prototype[method] = donator[method];
|
|
66
|
+
for (var meth in donator) {
|
|
67
|
+
target[meth] = donator[meth];
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
if (klass.$included_in) {
|
|
61
|
-
|
|
71
|
+
// klass._donate(methods.slice(), true);
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
|
|
@@ -69,24 +79,20 @@ class Module
|
|
|
69
79
|
%x{
|
|
70
80
|
function define_attr(klass, name, getter, setter) {
|
|
71
81
|
if (getter) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
klass.prototype[get_jsid] = function() {
|
|
75
|
-
var res = this[name];
|
|
82
|
+
klass.$m_tbl[name] = function() {
|
|
83
|
+
var res = #{self}[name];
|
|
76
84
|
return res == null ? nil : res;
|
|
77
85
|
};
|
|
78
86
|
|
|
79
|
-
klass._donate([
|
|
87
|
+
klass._donate([name]);
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
if (setter) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
klass.prototype[set_jsid] = function(val) {
|
|
86
|
-
return this[name] = val;
|
|
91
|
+
klass.$m_tbl[name + '='] = function(val) {
|
|
92
|
+
return #{self}[name] = val;
|
|
87
93
|
};
|
|
88
94
|
|
|
89
|
-
klass._donate([
|
|
95
|
+
klass._donate([name]);
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
}
|
|
@@ -94,7 +100,7 @@ class Module
|
|
|
94
100
|
def attr_accessor(*attrs)
|
|
95
101
|
%x{
|
|
96
102
|
for (var i = 0, length = attrs.length; i < length; i++) {
|
|
97
|
-
define_attr(
|
|
103
|
+
define_attr(#{self}, attrs[i], true, true);
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
return nil;
|
|
@@ -104,7 +110,7 @@ class Module
|
|
|
104
110
|
def attr_reader(*attrs)
|
|
105
111
|
%x{
|
|
106
112
|
for (var i = 0, length = attrs.length; i < length; i++) {
|
|
107
|
-
define_attr(
|
|
113
|
+
define_attr(#{self}, attrs[i], true, false);
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
return nil;
|
|
@@ -114,7 +120,7 @@ class Module
|
|
|
114
120
|
def attr_writer(*attrs)
|
|
115
121
|
%x{
|
|
116
122
|
for (var i = 0, length = attrs.length; i < length; i++) {
|
|
117
|
-
define_attr(
|
|
123
|
+
define_attr(#{self}, attrs[i], false, true);
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
return nil;
|
|
@@ -122,7 +128,7 @@ class Module
|
|
|
122
128
|
end
|
|
123
129
|
|
|
124
130
|
def attr(name, setter = false)
|
|
125
|
-
`define_attr(
|
|
131
|
+
`define_attr(#{self}, name, true, setter)`
|
|
126
132
|
|
|
127
133
|
self
|
|
128
134
|
end
|
|
@@ -133,12 +139,11 @@ class Module
|
|
|
133
139
|
no_block_given();
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
|
|
137
|
-
block.
|
|
138
|
-
block._sup = this.prototype[jsid];
|
|
142
|
+
block._jsid = name;
|
|
143
|
+
block._sup = #{self}.$m_tbl[name];
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
#{self}.$m_tbl[name] = block;
|
|
146
|
+
#{self}._donate([name]);
|
|
142
147
|
|
|
143
148
|
return nil;
|
|
144
149
|
}
|
|
@@ -151,15 +156,15 @@ class Module
|
|
|
151
156
|
mod = mods[i];
|
|
152
157
|
i--;
|
|
153
158
|
|
|
154
|
-
if (mod ===
|
|
159
|
+
if (mod === #{self}) {
|
|
155
160
|
continue;
|
|
156
161
|
}
|
|
157
|
-
|
|
158
|
-
mod
|
|
159
|
-
mod
|
|
162
|
+
|
|
163
|
+
#{ `mod`.append_features self };
|
|
164
|
+
#{ `mod`.included self };
|
|
160
165
|
}
|
|
161
166
|
|
|
162
|
-
return
|
|
167
|
+
return #{self};
|
|
163
168
|
}
|
|
164
169
|
end
|
|
165
170
|
|
|
@@ -177,31 +182,29 @@ class Module
|
|
|
177
182
|
no_block_given();
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
return block
|
|
185
|
+
return block(#{self});
|
|
181
186
|
}
|
|
182
187
|
end
|
|
183
188
|
|
|
184
189
|
alias class_eval module_eval
|
|
185
190
|
|
|
186
191
|
def name
|
|
187
|
-
|
|
192
|
+
`#{self}._name`
|
|
188
193
|
end
|
|
189
194
|
|
|
190
195
|
alias public_instance_methods instance_methods
|
|
191
196
|
|
|
192
197
|
def singleton_class
|
|
193
198
|
%x{
|
|
194
|
-
if (
|
|
195
|
-
return
|
|
199
|
+
if (#{self}._singleton) {
|
|
200
|
+
return #{self}._singleton;
|
|
196
201
|
}
|
|
197
|
-
else {
|
|
198
|
-
var meta = new __opal.Class;
|
|
199
|
-
this._klass = meta;
|
|
200
|
-
meta._isSingleton = true;
|
|
201
|
-
meta.prototype = this;
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
}
|
|
203
|
+
var meta = new __opal.Class;
|
|
204
|
+
#{self}._singleton = meta;
|
|
205
|
+
meta.$m_tbl = #{self}.$m;
|
|
206
|
+
|
|
207
|
+
return meta;
|
|
205
208
|
}
|
|
206
209
|
end
|
|
207
210
|
|
data/core/numeric.rb
CHANGED
|
@@ -6,79 +6,79 @@ class Numeric < `Number`
|
|
|
6
6
|
include Comparable
|
|
7
7
|
|
|
8
8
|
def +(other)
|
|
9
|
-
|
|
9
|
+
`#{self} + other`
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def -(other)
|
|
13
|
-
|
|
13
|
+
`#{self} - other`
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def *(other)
|
|
17
|
-
|
|
17
|
+
`#{self} * other`
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def /(other)
|
|
21
|
-
|
|
21
|
+
`#{self} / other`
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def %(other)
|
|
25
|
-
|
|
25
|
+
`#{self} % other`
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def &(other)
|
|
29
|
-
|
|
29
|
+
`#{self} & other`
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def |(other)
|
|
33
|
-
|
|
33
|
+
`#{self} | other`
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def ^(other)
|
|
37
|
-
|
|
37
|
+
`#{self} ^ other`
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def <(other)
|
|
41
|
-
|
|
41
|
+
`#{self} < other`
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def <=(other)
|
|
45
|
-
|
|
45
|
+
`#{self} <= other`
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def >(other)
|
|
49
|
-
|
|
49
|
+
`#{self} > other`
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def >=(other)
|
|
53
|
-
|
|
53
|
+
`#{self} >= other`
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def <<(count)
|
|
57
|
-
|
|
57
|
+
`#{self} << count`
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def >>(count)
|
|
61
|
-
|
|
61
|
+
`#{self} >> count`
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def +@
|
|
65
|
-
|
|
65
|
+
`+#{self}`
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def -@
|
|
69
|
-
|
|
69
|
+
`-#{self}`
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def ~
|
|
73
|
-
|
|
73
|
+
`~#{self}`
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def **(other)
|
|
77
|
-
`Math.pow(
|
|
77
|
+
`Math.pow(#{self}, other)`
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def ==(other)
|
|
81
|
-
|
|
81
|
+
`#{self} == other`
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def <=>(other)
|
|
@@ -87,52 +87,52 @@ class Numeric < `Number`
|
|
|
87
87
|
return nil;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
return
|
|
90
|
+
return #{self} < other ? -1 : (#{self} > other ? 1 : 0);
|
|
91
91
|
}
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
def abs
|
|
95
|
-
`Math.abs(
|
|
95
|
+
`Math.abs(#{self})`
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def ceil
|
|
99
|
-
`Math.ceil(
|
|
99
|
+
`Math.ceil(#{self})`
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def chr
|
|
103
|
-
`String.fromCharCode(
|
|
103
|
+
`String.fromCharCode(#{self})`
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def downto(finish, &block)
|
|
107
107
|
return enum_for :downto, finish unless block_given?
|
|
108
108
|
|
|
109
109
|
%x{
|
|
110
|
-
for (var i =
|
|
110
|
+
for (var i = #{self}; i >= finish; i--) {
|
|
111
111
|
if (block.call(__context, i) === __breaker) {
|
|
112
112
|
return __breaker.$v;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
return
|
|
116
|
+
return #{self};
|
|
117
117
|
}
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
alias eql? ==
|
|
121
121
|
|
|
122
122
|
def even?
|
|
123
|
-
|
|
123
|
+
`#{self} % 2 === 0`
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
def floor
|
|
127
|
-
`Math.floor(
|
|
127
|
+
`Math.floor(#{self})`
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
def hash
|
|
131
|
-
|
|
131
|
+
`#{self}.toString()`
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
def integer?
|
|
135
|
-
|
|
135
|
+
`#{self} % 1 === 0`
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
alias magnitude abs
|
|
@@ -140,15 +140,15 @@ class Numeric < `Number`
|
|
|
140
140
|
alias modulo %
|
|
141
141
|
|
|
142
142
|
def next
|
|
143
|
-
|
|
143
|
+
`#{self} + 1`
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
def nonzero?
|
|
147
|
-
|
|
147
|
+
`#{self}.valueOf() === 0 ? nil : #{self}`
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
def odd?
|
|
151
|
-
|
|
151
|
+
`#{self} % 2 !== 0`
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
def ord
|
|
@@ -156,7 +156,7 @@ class Numeric < `Number`
|
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
def pred
|
|
159
|
-
|
|
159
|
+
`#{self} - 1`
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
alias succ next
|
|
@@ -165,30 +165,30 @@ class Numeric < `Number`
|
|
|
165
165
|
return enum_for :times unless block_given?
|
|
166
166
|
|
|
167
167
|
%x{
|
|
168
|
-
for (var i = 0; i <=
|
|
168
|
+
for (var i = 0; i <= #{self}; i++) {
|
|
169
169
|
if (block.call(__context, i) === __breaker) {
|
|
170
170
|
return __breaker.$v;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
return
|
|
174
|
+
return #{self};
|
|
175
175
|
}
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
def to_f
|
|
179
|
-
`parseFloat(
|
|
179
|
+
`parseFloat(#{self})`
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
def to_i
|
|
183
|
-
`parseInt(
|
|
183
|
+
`parseInt(#{self})`
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
def to_json
|
|
187
|
-
|
|
187
|
+
`#{self}.toString()`
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
def to_s(base = 10)
|
|
191
|
-
|
|
191
|
+
`#{self}.toString()`
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
def upto(finish, &block)
|
|
@@ -201,11 +201,11 @@ class Numeric < `Number`
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
return
|
|
204
|
+
return #{self};
|
|
205
205
|
}
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
def zero?
|
|
209
|
-
|
|
209
|
+
`#{self} == 0`
|
|
210
210
|
end
|
|
211
211
|
end
|