opal 0.3.6 → 0.3.9
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/README.md +69 -97
- data/bin/opal +2 -2
- data/{lib/core → corelib}/array.rb +85 -56
- data/corelib/boolean.rb +20 -0
- data/corelib/class.rb +58 -0
- data/{lib → corelib}/core.rb +2 -50
- data/corelib/dir.rb +22 -0
- data/{lib/core → corelib}/enumerable.rb +0 -0
- data/corelib/error.rb +19 -0
- data/{lib/core → corelib}/file.rb +7 -9
- data/{lib/core → corelib}/hash.rb +104 -144
- data/{lib/core → corelib}/kernel.rb +38 -44
- data/corelib/load_order +21 -0
- data/{lib/core → corelib}/match_data.rb +0 -0
- data/{lib/core → corelib}/module.rb +12 -8
- data/{lib/core → corelib}/nil_class.rb +2 -2
- data/{lib/core → corelib}/numeric.rb +37 -100
- data/corelib/object.rb +37 -0
- data/{lib/core → corelib}/proc.rb +3 -3
- data/corelib/range.rb +27 -0
- data/{lib/core → corelib}/regexp.rb +1 -1
- data/{lib/core → corelib}/string.rb +16 -107
- data/{lib/core → corelib}/top_self.rb +0 -0
- data/lib/opal.rb +7 -0
- data/lib/opal/browserify.rb +34 -0
- data/{opal_lib → lib}/opal/builder.rb +70 -24
- data/lib/opal/command.rb +52 -0
- data/lib/opal/context.rb +197 -0
- data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
- data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
- data/lib/opal/parser.rb +4894 -0
- data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
- data/lib/rbp.rb +2 -0
- data/lib/rbp/package.rb +49 -0
- data/runtime/class.js +216 -189
- data/runtime/fs.js +2 -2
- data/runtime/init.js +242 -244
- data/runtime/loader.js +78 -99
- data/runtime/module.js +34 -40
- data/runtime/post.js +2 -2
- data/runtime/pre.js +1 -1
- data/runtime/runtime.js +129 -135
- data/{lib → stdlib}/dev.rb +10 -10
- data/{lib → stdlib}/racc/parser.rb +0 -6
- data/{lib → stdlib}/strscan.rb +4 -4
- metadata +57 -105
- data/lib/core/basic_object.rb +0 -51
- data/lib/core/class.rb +0 -38
- data/lib/core/dir.rb +0 -26
- data/lib/core/error.rb +0 -75
- data/lib/core/false_class.rb +0 -81
- data/lib/core/object.rb +0 -6
- data/lib/core/range.rb +0 -27
- data/lib/core/symbol.rb +0 -42
- data/lib/core/true_class.rb +0 -41
- data/lib/ospec.rb +0 -7
- data/lib/ospec/autorun.rb +0 -8
- data/lib/ospec/dsl.rb +0 -15
- data/lib/ospec/example.rb +0 -11
- data/lib/ospec/example/before_and_after_hooks.rb +0 -56
- data/lib/ospec/example/errors.rb +0 -17
- data/lib/ospec/example/example_group.rb +0 -12
- data/lib/ospec/example/example_group_factory.rb +0 -18
- data/lib/ospec/example/example_group_hierarchy.rb +0 -21
- data/lib/ospec/example/example_group_methods.rb +0 -100
- data/lib/ospec/example/example_group_proxy.rb +0 -15
- data/lib/ospec/example/example_methods.rb +0 -46
- data/lib/ospec/example/example_proxy.rb +0 -18
- data/lib/ospec/expectations.rb +0 -19
- data/lib/ospec/expectations/errors.rb +0 -8
- data/lib/ospec/expectations/fail_with.rb +0 -9
- data/lib/ospec/expectations/handler.rb +0 -33
- data/lib/ospec/helpers/scratch.rb +0 -18
- data/lib/ospec/matchers.rb +0 -24
- data/lib/ospec/matchers/be.rb +0 -1
- data/lib/ospec/matchers/generated_descriptions.rb +0 -20
- data/lib/ospec/matchers/operator_matcher.rb +0 -54
- data/lib/ospec/matchers/raise_error.rb +0 -38
- data/lib/ospec/runner.rb +0 -90
- data/lib/ospec/runner/example_group_runner.rb +0 -41
- data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
- data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
- data/lib/ospec/runner/options.rb +0 -34
- data/lib/ospec/runner/reporter.rb +0 -82
- data/opal_lib/opal.rb +0 -16
- data/opal_lib/opal/build_methods.rb +0 -51
- data/opal_lib/opal/bundle.rb +0 -70
- data/opal_lib/opal/command.rb +0 -68
- data/opal_lib/opal/context.rb +0 -81
- data/opal_lib/opal/context/console.rb +0 -10
- data/opal_lib/opal/context/file_system.rb +0 -34
- data/opal_lib/opal/context/loader.rb +0 -135
- data/opal_lib/opal/gem.rb +0 -84
- data/opal_lib/opal/rake/builder_task.rb +0 -44
- data/opal_lib/opal/rake/spec_task.rb +0 -32
- data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
- data/opal_lib/opal/version.rb +0 -4
- data/runtime/debug.js +0 -84
data/README.md
CHANGED
|
@@ -1,126 +1,98 @@
|
|
|
1
|
-
Opal
|
|
2
|
-
|
|
1
|
+
Opal
|
|
2
|
+
====
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
Opal is a partial implementation of ruby designed to run in any
|
|
5
|
+
javascript environment. The runtime is written in javascript, with all
|
|
6
|
+
core libraries written directly in ruby with inline javascript to make
|
|
7
|
+
them as fast as possible.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
Wherever possible ruby objects are mapped directly onto their native
|
|
10
|
+
javascript counterparts to speed up the generated code and to improve
|
|
11
|
+
interopability with existing javascript libraries.
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
line through the bundled build tools. Opal includes a parser/compiler
|
|
13
|
-
that builds ruby ahead of time directly into javascript that runs with
|
|
14
|
-
the bundled runtime.
|
|
13
|
+
The opal compiler is a source-to-source compiler which outputs
|
|
14
|
+
javascript which can then run on the core runtime.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Opal does not aim to be 100% comaptible with other ruby implementations,
|
|
17
|
+
but does so where the generated code can be efficient on all modern web
|
|
18
|
+
browsers - including older versions of IE and mobile devices.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* Private and public method support
|
|
22
|
-
* Full operator overloading (`[]`, `[]=`, `+`, `-`, `==`, etc)
|
|
23
|
-
* Toll free bridges to javascript objects (`String`, `Number`, `Array`
|
|
24
|
-
etc)
|
|
25
|
-
* Inline javascript within ruby code using backticks
|
|
26
|
-
* In browser loading of `<script type="text/ruby></script>` tags
|
|
27
|
-
* Generated code is clean and maintains line numbers to ease debugging
|
|
28
|
-
* super(), metaclasses, eigenclasses, blocks, yield, block\_given?,
|
|
29
|
-
ranges, arg count errors, lambda, singletons, etc....
|
|
20
|
+
Using opal
|
|
21
|
+
----------
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
Opal can currently be used in two ways: through a distributed ruby gem,
|
|
24
|
+
or directly in the web browser.
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
`opal` bin file directly:
|
|
26
|
+
### Using the gem
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
Install via ruby gems:
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
```
|
|
31
|
+
$ gem install opal
|
|
32
|
+
```
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
The `opal` command should then be available. To run the simple repl use:
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
evaluated within the browser (no plugins!).
|
|
36
|
+
```
|
|
37
|
+
opal irb
|
|
38
|
+
```
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
The `opal` command can also be used directly from this source repo, so
|
|
41
|
+
to download and run opal:
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
```
|
|
44
|
+
$ git clone https://github.com/adambeynon/opal.git
|
|
45
|
+
$ cd opal
|
|
46
|
+
$ bin/opal
|
|
47
|
+
```
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### Browser
|
|
60
|
-
|
|
61
|
-
To run within the browser, you can either use the latest build version
|
|
62
|
-
on the opal website, or clone the build tools as above, and then run the
|
|
63
|
-
following task in this directory:
|
|
64
|
-
|
|
65
|
-
$ rake opal
|
|
66
|
-
|
|
67
|
-
This will place a non minified version ready to run within the browser
|
|
68
|
-
into `extras/opal.js`
|
|
69
|
-
|
|
70
|
-
#### Compiling ruby sources
|
|
71
|
-
|
|
72
|
-
To run ruby code in the browser, ruby must either be precompiled to
|
|
73
|
-
javascript using these build tools, or the `opal_dev.js` file can parse
|
|
74
|
-
and compile ruby code referenced in html `script` tags that use the
|
|
75
|
-
`text/ruby` type.
|
|
76
|
-
|
|
77
|
-
### Command line
|
|
78
|
-
|
|
79
|
-
Opal is bundled with a set of build tools available in the `opalite/`
|
|
80
|
-
directory. These are available when running opal from the command line
|
|
81
|
-
or including it from ruby sources.
|
|
82
|
-
|
|
83
|
-
#### Ruby repl
|
|
84
|
-
|
|
85
|
-
To run the repl, clone this repo as directed above and run:
|
|
49
|
+
Running tests
|
|
50
|
+
-------------
|
|
86
51
|
|
|
87
|
-
|
|
52
|
+
To run tests, you need opaltest which is the testing framework for opal
|
|
53
|
+
based on minitest. To get opaltest, run the following in the opal
|
|
54
|
+
directory:
|
|
88
55
|
|
|
89
|
-
|
|
90
|
-
|
|
56
|
+
```
|
|
57
|
+
$ rake vendor
|
|
58
|
+
```
|
|
91
59
|
|
|
92
|
-
|
|
93
|
-
|
|
60
|
+
This will put opaltest into `vendor/opaltest` so it will be available
|
|
61
|
+
for running. To test `array.rb` for example, run:
|
|
94
62
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
or built ready to open in the browser.
|
|
63
|
+
```
|
|
64
|
+
$ bin/opal test/array.rb
|
|
65
|
+
```
|
|
99
66
|
|
|
100
|
-
|
|
67
|
+
The results should be printed to the console.
|
|
101
68
|
|
|
102
|
-
|
|
69
|
+
Differences from ruby
|
|
70
|
+
---------------------
|
|
103
71
|
|
|
104
|
-
|
|
72
|
+
### No method\_missing
|
|
105
73
|
|
|
106
|
-
|
|
107
|
-
in
|
|
74
|
+
To optimize method dispatch, `method_missing` is not supported in opal.
|
|
75
|
+
It is supported in debug mode to improve readability of error messages
|
|
76
|
+
from calling undefined methods, but should/will not be used in
|
|
77
|
+
production code.
|
|
108
78
|
|
|
109
|
-
###
|
|
79
|
+
### Immutable strings and removed symbols
|
|
110
80
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
81
|
+
All strings in opal are immutable to make them easier to map onto
|
|
82
|
+
javascript strings. In opal a ruby string compiles directly into a js
|
|
83
|
+
string without a wrapper so that they can be passed back between code
|
|
84
|
+
bases easily. Also, symbol syntax is maintained, but all symbols just
|
|
85
|
+
compile into javascript strings. The `Symbol` class is also therefore
|
|
86
|
+
removed.
|
|
114
87
|
|
|
115
|
-
|
|
88
|
+
### Unified Numeric class
|
|
116
89
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
gem release and version bump.
|
|
90
|
+
All numbers in opal are members of the `Numeric` class. The `Integer`
|
|
91
|
+
and `Float` classes are removed.
|
|
120
92
|
|
|
121
|
-
|
|
122
|
-
--------
|
|
93
|
+
### Unified Boolean class
|
|
123
94
|
|
|
124
|
-
|
|
125
|
-
|
|
95
|
+
Both `true` and `false` compile into their native javascript
|
|
96
|
+
counterparts which means that they both become instances of the
|
|
97
|
+
`Boolean` class and opal removes the `TrueClass` and `FalseClass`.
|
|
126
98
|
|
data/bin/opal
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
opal_lib = File.expand_path('../../
|
|
3
|
+
opal_lib = File.expand_path('../../lib', __FILE__)
|
|
4
4
|
$:.unshift opal_lib unless $:.include? opal_lib
|
|
5
5
|
|
|
6
6
|
require 'opal'
|
|
7
7
|
require 'opal/command'
|
|
8
8
|
|
|
9
|
-
Opal::Command.
|
|
9
|
+
Opal::Command.new ARGV
|
|
10
10
|
|
|
@@ -16,20 +16,16 @@ class Array
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.allocate
|
|
19
|
-
`var
|
|
20
|
-
|
|
21
|
-
arr.$m = self.$m_tbl;
|
|
22
|
-
return arr;`
|
|
19
|
+
`var ary = new self.$a();
|
|
20
|
+
return ary;`
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
def initialize(len, fill = nil)
|
|
26
|
-
`var
|
|
27
|
-
|
|
28
|
-
for (var i = 0; i < len; i++) {
|
|
29
|
-
ary[i] = fill;
|
|
23
|
+
def initialize(len = 0, fill = nil)
|
|
24
|
+
`for (var i = 0; i < len; i++) {
|
|
25
|
+
self[i] = fill;
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
self.length = len;
|
|
33
29
|
|
|
34
30
|
return self;`
|
|
35
31
|
end
|
|
@@ -120,9 +116,9 @@ class Array
|
|
|
120
116
|
def each_with_index
|
|
121
117
|
raise "Array#each_with_index no block given" unless block_given?
|
|
122
118
|
|
|
123
|
-
`for (var i = 0, len = self.length; i < len; i++) {
|
|
124
|
-
|
|
125
|
-
}`
|
|
119
|
+
`for (var i = 0, len = self.length; i < len; i++) {`
|
|
120
|
+
yield `self[i]`, `i`
|
|
121
|
+
`}`
|
|
126
122
|
self
|
|
127
123
|
end
|
|
128
124
|
|
|
@@ -235,16 +231,16 @@ class Array
|
|
|
235
231
|
# @param [Array] other array to compare self with
|
|
236
232
|
# @return [Boolean] if the arrays are equal
|
|
237
233
|
def ==(other)
|
|
238
|
-
`if (self.$
|
|
239
|
-
if (self.length != other.length) return
|
|
234
|
+
`if (self.$h() == other.$h()) return true;
|
|
235
|
+
if (self.length != other.length) return false;
|
|
240
236
|
|
|
241
237
|
for (var i = 0; i < self.length; i++) {
|
|
242
|
-
if (!#{`self[i]` == `other[i]`}
|
|
243
|
-
return
|
|
238
|
+
if (!#{`self[i]` == `other[i]`}) {
|
|
239
|
+
return false;
|
|
244
240
|
}
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
return
|
|
243
|
+
return true;`
|
|
248
244
|
end
|
|
249
245
|
|
|
250
246
|
# Searches through an array whose elements are also arrays, comparing `obj`
|
|
@@ -288,9 +284,11 @@ class Array
|
|
|
288
284
|
# @param [Numeric] index the index to get
|
|
289
285
|
# @return [Object, nil] returns nil or the result
|
|
290
286
|
def at(idx)
|
|
291
|
-
`
|
|
287
|
+
`var size = self.length;
|
|
292
288
|
|
|
293
|
-
if (idx < 0
|
|
289
|
+
if (idx < 0) idx += size;
|
|
290
|
+
|
|
291
|
+
if (idx < 0 || idx >= size) return nil;
|
|
294
292
|
return self[idx];`
|
|
295
293
|
end
|
|
296
294
|
|
|
@@ -457,7 +455,7 @@ class Array
|
|
|
457
455
|
#
|
|
458
456
|
# @param [Object] obj object to check
|
|
459
457
|
# @return [Numeric] count or count of obj
|
|
460
|
-
def count(obj)
|
|
458
|
+
def count(obj = undefined)
|
|
461
459
|
`if (obj != undefined) {
|
|
462
460
|
var total = 0;
|
|
463
461
|
|
|
@@ -594,7 +592,7 @@ class Array
|
|
|
594
592
|
#
|
|
595
593
|
# @return [false, true] empty or not
|
|
596
594
|
def empty?
|
|
597
|
-
`return self.length == 0
|
|
595
|
+
`return self.length == 0;`
|
|
598
596
|
end
|
|
599
597
|
|
|
600
598
|
# Tries to return the element as position `index`. If the index lies outside
|
|
@@ -624,13 +622,13 @@ class Array
|
|
|
624
622
|
# @param [Numeric] idx
|
|
625
623
|
# @param [Object] defaults
|
|
626
624
|
# @return [Object] returns result
|
|
627
|
-
def fetch(idx, defaults)
|
|
625
|
+
def fetch(idx, defaults = undefined)
|
|
628
626
|
`var original = idx;
|
|
629
627
|
|
|
630
628
|
if (idx < 0) idx += self.length;
|
|
631
629
|
if (idx < 0 || idx >= self.length) {
|
|
632
630
|
if (defaults == undefined)
|
|
633
|
-
|
|
631
|
+
raise(eIndexError, "Array#fetch");
|
|
634
632
|
else if (__block__)
|
|
635
633
|
return #{yield `original`};
|
|
636
634
|
else
|
|
@@ -654,8 +652,8 @@ class Array
|
|
|
654
652
|
#
|
|
655
653
|
# @param [Numeric] count number of elements
|
|
656
654
|
# @return [Object, Array] object or array of objects
|
|
657
|
-
def first(count =
|
|
658
|
-
`if (count ==
|
|
655
|
+
def first(count = undefined)
|
|
656
|
+
`if (count == undefined) {
|
|
659
657
|
if (self.length == 0) return nil;
|
|
660
658
|
return self[0];
|
|
661
659
|
}
|
|
@@ -683,14 +681,14 @@ class Array
|
|
|
683
681
|
#
|
|
684
682
|
# @param [Numeric] level the level to flatten
|
|
685
683
|
# @return [Array] returns new array
|
|
686
|
-
def flatten(level =
|
|
684
|
+
def flatten(level = undefined)
|
|
687
685
|
`var result = [], item;
|
|
688
686
|
|
|
689
687
|
for (var i = 0; i < self.length; i++) {
|
|
690
688
|
item = self[i];
|
|
691
689
|
|
|
692
|
-
if (item.
|
|
693
|
-
if (level ==
|
|
690
|
+
if (item.o$f & T_ARRAY) {
|
|
691
|
+
if (level == undefined)
|
|
694
692
|
result = result.concat(#{`item`.flatten});
|
|
695
693
|
else if (level == 0)
|
|
696
694
|
result.push(item);
|
|
@@ -719,7 +717,7 @@ class Array
|
|
|
719
717
|
#
|
|
720
718
|
# @param [Number] level to flatten to
|
|
721
719
|
# @return [Array] returns the receiver
|
|
722
|
-
def flatten!(level =
|
|
720
|
+
def flatten!(level = undefined)
|
|
723
721
|
`var length = self.length;
|
|
724
722
|
var result = #{self.flatten level};
|
|
725
723
|
self.splice(0);
|
|
@@ -734,6 +732,20 @@ class Array
|
|
|
734
732
|
return self;`
|
|
735
733
|
end
|
|
736
734
|
|
|
735
|
+
def grep(pattern)
|
|
736
|
+
`var result = [], arg;
|
|
737
|
+
|
|
738
|
+
for (var i = 0, ii = self.length; i < ii; i++) {
|
|
739
|
+
arg = self[i];
|
|
740
|
+
|
|
741
|
+
if (pattern.exec(arg)) {
|
|
742
|
+
result.push(arg);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return result;`
|
|
747
|
+
end
|
|
748
|
+
|
|
737
749
|
# Returns true if the given object is present in `self`, false otherwise.
|
|
738
750
|
#
|
|
739
751
|
# @example
|
|
@@ -745,7 +757,7 @@ class Array
|
|
|
745
757
|
# # => false
|
|
746
758
|
def include?(member)
|
|
747
759
|
`for (var i = 0; i < self.length; i++) {
|
|
748
|
-
if (#{`self[i]` == member}
|
|
760
|
+
if (#{`self[i]` == member}) {
|
|
749
761
|
return #{true};
|
|
750
762
|
}
|
|
751
763
|
}
|
|
@@ -753,6 +765,17 @@ class Array
|
|
|
753
765
|
return #{false};`
|
|
754
766
|
end
|
|
755
767
|
|
|
768
|
+
def inject(initial = undefined)
|
|
769
|
+
`if (initial === undefined) initial = self[0];
|
|
770
|
+
var result;
|
|
771
|
+
|
|
772
|
+
for (var i = 0, ii = self.length; i < ii; i++) {
|
|
773
|
+
initial = #{ yield `initial`, `self[i]` };
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
return initial;`
|
|
777
|
+
end
|
|
778
|
+
|
|
756
779
|
# Replaces the contents of `self` with the contents of `other`, truncating or
|
|
757
780
|
# expanding if necessary.
|
|
758
781
|
#
|
|
@@ -791,10 +814,12 @@ class Array
|
|
|
791
814
|
# @param [Object] objs objects to insert
|
|
792
815
|
# @return [Array] returns the receiver
|
|
793
816
|
def insert(idx, *objs)
|
|
794
|
-
`
|
|
817
|
+
`var size = self.length;
|
|
795
818
|
|
|
796
|
-
if (idx < 0
|
|
797
|
-
|
|
819
|
+
if (idx < 0) idx += size;
|
|
820
|
+
|
|
821
|
+
if (idx < 0 || idx >= size)
|
|
822
|
+
raise(eIndexError, "out of range");
|
|
798
823
|
|
|
799
824
|
self.splice.apply(self, [idx, 0].concat(objs));
|
|
800
825
|
return self;`
|
|
@@ -855,13 +880,15 @@ class Array
|
|
|
855
880
|
#
|
|
856
881
|
# @param [Number] count the number of items to get
|
|
857
882
|
# @return [Object, Array] result
|
|
858
|
-
def last(count =
|
|
859
|
-
`
|
|
860
|
-
|
|
861
|
-
|
|
883
|
+
def last(count = undefined)
|
|
884
|
+
`var size = self.length;
|
|
885
|
+
|
|
886
|
+
if (count == undefined) {
|
|
887
|
+
if (size == 0) return nil;
|
|
888
|
+
return self[size - 1];
|
|
862
889
|
} else {
|
|
863
|
-
if (count >
|
|
864
|
-
return self.slice(
|
|
890
|
+
if (count > size) count = size;
|
|
891
|
+
return self.slice(size - count, size);
|
|
865
892
|
}`
|
|
866
893
|
end
|
|
867
894
|
|
|
@@ -881,12 +908,14 @@ class Array
|
|
|
881
908
|
#
|
|
882
909
|
# @param [Numeric] count number to pop
|
|
883
910
|
# @return [Array] returns popped items
|
|
884
|
-
def pop(count =
|
|
885
|
-
`
|
|
886
|
-
|
|
911
|
+
def pop(count = undefined)
|
|
912
|
+
`var size = self.length;
|
|
913
|
+
|
|
914
|
+
if (count == undefined) {
|
|
915
|
+
if (size) return self.pop();
|
|
887
916
|
return nil;
|
|
888
917
|
} else {
|
|
889
|
-
return self.splice(
|
|
918
|
+
return self.splice(size - count, size);
|
|
890
919
|
}`
|
|
891
920
|
end
|
|
892
921
|
|
|
@@ -909,7 +938,7 @@ class Array
|
|
|
909
938
|
|
|
910
939
|
for (var i = 0; i < self.length; i++) {
|
|
911
940
|
test = self[i];
|
|
912
|
-
if (test.
|
|
941
|
+
if (test.o$f & T_ARRAY && test[1] != undefined) {
|
|
913
942
|
if (#{`test[1]` == obj}.$r) return test;
|
|
914
943
|
}
|
|
915
944
|
}
|
|
@@ -1048,7 +1077,7 @@ class Array
|
|
|
1048
1077
|
# # => 3
|
|
1049
1078
|
#
|
|
1050
1079
|
# @return [Object, nil] returns result or nil
|
|
1051
|
-
def rindex(obj =
|
|
1080
|
+
def rindex(obj = undefined)
|
|
1052
1081
|
`if (obj != undefined) {
|
|
1053
1082
|
for (var i = self.length - 1; i >=0; i--) {
|
|
1054
1083
|
if (#{`self[i]` == obj}.$r) {
|
|
@@ -1056,7 +1085,7 @@ class Array
|
|
|
1056
1085
|
}
|
|
1057
1086
|
}
|
|
1058
1087
|
} else if (true || __block__) {
|
|
1059
|
-
|
|
1088
|
+
raise(eException, "Array#rindex needs to do block action");
|
|
1060
1089
|
}
|
|
1061
1090
|
|
|
1062
1091
|
return nil;`
|
|
@@ -1111,11 +1140,11 @@ class Array
|
|
|
1111
1140
|
#
|
|
1112
1141
|
# @param [Numeric] count elements to shift
|
|
1113
1142
|
# @return [Array] result
|
|
1114
|
-
def shift(count =
|
|
1115
|
-
`if (count !=
|
|
1143
|
+
def shift(count = undefined)
|
|
1144
|
+
`if (count != undefined)
|
|
1116
1145
|
return self.splice(0, count);
|
|
1117
1146
|
|
|
1118
|
-
if (self.length)
|
|
1147
|
+
if (self.length)
|
|
1119
1148
|
return self.shift();
|
|
1120
1149
|
|
|
1121
1150
|
return nil;`
|
|
@@ -1226,7 +1255,7 @@ class Array
|
|
|
1226
1255
|
`var result = [], seen = [];
|
|
1227
1256
|
|
|
1228
1257
|
for (var i = 0; i < self.length; i++) {
|
|
1229
|
-
var test = self[i], hash = test.$
|
|
1258
|
+
var test = self[i], hash = test.$h();
|
|
1230
1259
|
if (seen.indexOf(hash) == -1) {
|
|
1231
1260
|
seen.push(hash);
|
|
1232
1261
|
result.push(test);
|
|
@@ -1252,7 +1281,7 @@ class Array
|
|
|
1252
1281
|
`var seen = [], length = self.length;
|
|
1253
1282
|
|
|
1254
1283
|
for (var i = 0; i < self.length; i++) {
|
|
1255
|
-
var test = self[i], hash = test.$
|
|
1284
|
+
var test = self[i], hash = test.$h();
|
|
1256
1285
|
if (seen.indexOf(hash) == -1) {
|
|
1257
1286
|
seen.push(hash);
|
|
1258
1287
|
} else {
|
|
@@ -1298,11 +1327,11 @@ class Array
|
|
|
1298
1327
|
`var result = [], seen = [];
|
|
1299
1328
|
|
|
1300
1329
|
for (var i = 0; i < self.length; i++) {
|
|
1301
|
-
var test = self[i], hash = test.$
|
|
1330
|
+
var test = self[i], hash = test.$h();
|
|
1302
1331
|
|
|
1303
1332
|
if (seen.indexOf(hash) == -1) {
|
|
1304
1333
|
for (var j = 0; j < other.length; j++) {
|
|
1305
|
-
var test_b = other[j], hash_b = test_b.$
|
|
1334
|
+
var test_b = other[j], hash_b = test_b.$h();
|
|
1306
1335
|
|
|
1307
1336
|
if ((hash == hash_b) && seen.indexOf(hash) == -1) {
|
|
1308
1337
|
seen.push(hash);
|
|
@@ -1332,7 +1361,7 @@ class Array
|
|
|
1332
1361
|
# @param [String, Number] num string or number used to join or concat
|
|
1333
1362
|
# @return [String, Array] depending on argument
|
|
1334
1363
|
def *(arg)
|
|
1335
|
-
`if (
|
|
1364
|
+
`if (arg.o$f & T_STRING) {
|
|
1336
1365
|
return #{self.join `arg`};
|
|
1337
1366
|
} else {
|
|
1338
1367
|
var result = [];
|
|
@@ -1369,7 +1398,7 @@ class Array
|
|
|
1369
1398
|
# @param [Range, Numeric] index to begin
|
|
1370
1399
|
# @param [Numeric] length last index
|
|
1371
1400
|
# @return [Array, Object, nil] result
|
|
1372
|
-
def [](index, length =
|
|
1401
|
+
def [](index, length = undefined)
|
|
1373
1402
|
`var ary = self, size = ary.length;
|
|
1374
1403
|
|
|
1375
1404
|
if (index < 0) index += size;
|