Commit Graph

79 Commits

Author SHA1 Message Date
John Bampton ea8964ef35 ruby: standardize whitespace 2022-10-31 16:25:56 +10:00
dearblue 586525f99a Add Array#{repeated_combination,repeated_permutation} methods
Ruby 1.9.2 feature.

ref: https://docs.ruby-lang.org/ja/3.1.0/method/Array/i/repeated_combination.html
ref: https://docs.ruby-lang.org/ja/3.1.0/method/Array/i/repeated_permutation.html
2021-12-12 21:28:03 +09:00
dearblue c4bca7cbb3 Align "wrong number of arguments" messages
Make "N for M" into the form "given N, expected M".

As I worked, I noticed that the `argnum_error()` function had a part to include the method name in the message.
I think this part is no longer needed by https://github.com/mruby/mruby/pull/5394.

  - Before this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: 'each': wrong number of arguments (1 for 0) (ArgumentError)
    ```

  - After this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: wrong number of arguments (given 1, expected 0) (ArgumentError)
    ```
2021-11-28 18:21:29 +09:00
dearblue 5ea26260fa Added Array#product method
Ruby-1.9.0 feature.

ref: https://docs.ruby-lang.org/ja/3.0.0/method/Array/i/product.html
2021-10-31 23:02:37 +09:00
dearblue 2d0b50f6f3 Avoid warnings with ruby -cw
```console
% for rb in `git ls-files '*/mrblib/*.rb' 'mrblib'`; do ruby30 -cw $rb > /dev/null; done
mrbgems/mruby-array-ext/mrblib/array.rb:389: warning: assigned but unused variable - ary
mrbgems/mruby-array-ext/mrblib/array.rb:663: warning: assigned but unused variable - len
mrbgems/mruby-hash-ext/mrblib/hash.rb:119: warning: possibly useless use of a variable in void context
mrbgems/mruby-hash-ext/mrblib/hash.rb:259: warning: assigned but unused variable - keys
mrbgems/mruby-io/mrblib/io.rb:229: warning: literal in condition
mrbgems/mruby-io/mrblib/io.rb:280: warning: literal in condition
mrbgems/mruby-string-ext/mrblib/string.rb:347: warning: assigned but unused variable - len
mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb:2: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
```
2021-06-28 23:21:47 +09:00
John Bampton dab5502e8a Run pre-commit with GitHub Actions
Running pre-commit with GitHub Actions now gives us more tests and coverage

Remove duplicate GitHub Actions for merge conflicts and trailing whitespace

Remove duplicate checks for markdownlint and yamllint from the GitHub Super-Linter

Add new custom pre-commit hook running with a shell script to sort alphabetically and uniquify codespell.txt

Add new pre-commit hook to check spelling with codespell

https://github.com/codespell-project/codespell

Fix spelling
2021-06-16 08:34:54 +10:00
Yukihiro "Matz" Matsumoto ae4c952d2e mruby-array-ext/array.c: implement Array#rotate in C.
The Ruby version of `Array#rotate!` generated a rotated array and
replaced the receiver, but the C version rotates the receiver array
in-place. So the performance is improved a lot both in speed and memory
consumption. Look for the comments in `array.c` for the in-place rotating
algorithm, if you are interested.
2021-05-15 17:26:36 +09:00
Yukihiro "Matz" Matsumoto 9422fdbc87 mruby-array-ext/array.c: implement Array#compact in C. 2021-05-14 10:39:41 +09:00
Yukihiro "Matz" Matsumoto bdb5d85adc array.rb: replace can't with cannot.
To avoid editor coloring failures.
2021-05-14 10:34:11 +09:00
Yukihiro "Matz" Matsumoto aff3743c12 array.rb: Array#uniq to return always Array.
Even called for subclass of `Array`, according to new Ruby3.0 behavior.
Other methods of `Array` behave as Ruby3.0 from the first hand.
2021-04-28 17:45:19 +09:00
Yukihiro "Matz" Matsumoto 737254588b array.rb: add Array#intersect? from Ruby3.0.1. 2021-04-17 17:38:44 +09:00
dearblue 7ef4e54370 Comment out warn used in the Array#fetch method
I get an error because the current mruby does not have a `Kernel#warn` method.
But the warning itself is useful and I'll just comment it out in case it's implemented in the future.
2021-02-20 18:19:00 +09:00
Yukihiro "Matz" Matsumoto d9bd77b180 Fix A.new([[1,2],3]).flatten to return Array. 2020-11-05 14:29:26 +09:00
Hiroshi Mimaki e24b4a1e19 Delete duplicated Array#delete_if. 2020-01-21 11:35:53 +09:00
KOBAYASHI Shuji ac29638a8a Fix the example of Array#intersection in the document [ci skip] 2019-10-14 18:22:00 +09:00
Yukihiro "Matz" Matsumoto bdacdfaea9 Add Array#intersection which is new in Ruby2.7. 2019-10-14 17:04:19 +09:00
Yukihiro "Matz" Matsumoto 682406a384 Move Array#difference just after Array#-. 2019-10-14 17:04:19 +09:00
Yukihiro "Matz" Matsumoto 67ea80b2bd Fixed a bug in Array#difference. 2019-10-14 17:04:19 +09:00
KOBAYASHI Shuji 1fb4e73981 Fix typo in Array#difference document [ci skip] 2019-09-20 09:28:56 +09:00
Yukihiro "Matz" Matsumoto 57a0132b41 Add filter aliases for Enumerable and Hash. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto f4117d81d2 Add Array#difference method from Ruby2.6. 2019-09-16 10:10:09 +09:00
KOBAYASHI Shuji fe6cf851bf Array#permutation with a negative argument should not yield
Before this patch:

  $ bin/mruby -e '[1].permutation(-1){|v| p v}'  #=> [1]

After this patch (same as Ruby):

  $ bin/mruby -e '[1].permutation(-1){|v| p v}'  #=> no output
2019-09-01 09:28:11 +09:00
KOBAYASHI Shuji 28d1f6cdc4 Array#(permutation|combination) without block should return self 2019-08-30 17:04:25 +09:00
KOBAYASHI Shuji 778310260c Drop dependency from mruby-array-ext to mruby-enum-ext 2019-07-26 11:48:53 +09:00
KOBAYASHI Shuji 5adef8ba44 Move Array#(append|prepend) from core to mruby-ary-ext
They are not included in ISO standard.
2019-04-06 17:40:51 +09:00
KOBAYASHI Shuji 6da3cd5d22 Move NONE to mrblib/enum.rb 2019-02-01 16:02:01 +09:00
Yukihiro "Matz" Matsumoto 7ed9bb3bd3 Fix wrong number of arguments in Array#fetch; fix #4170 2018-11-25 06:05:07 +09:00
Yukihiro "Matz" Matsumoto 698f5f707c Removed to_ary conversion method. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 5bbcea9b3b Removed try_convert method from Array and Hash. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 426c1f9e0b fix non-ASCII comment. 2018-11-19 11:28:03 +09:00
Yukihiro "Matz" Matsumoto ab0f4db688 Call uniq! for each union processing in Array#union. 2018-10-12 19:00:14 +09:00
Yukihiro "Matz" Matsumoto d78acc7afe Add index to larger segment lists for performance 2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto f23f2bbdad Implement Array#union which is introduced in Ruby2.6. 2018-09-21 00:01:48 +09:00
Yukihiro "Matz" Matsumoto dd346be99a Improve performance of Array#uniq!. 2018-09-20 23:56:53 +09:00
Yukihiro "Matz" Matsumoto 19d3bb2d90 Make #to_h to take a block; [ruby-core:89088] 2018-09-20 13:47:29 +09:00
Tomasz Dąbrowski e65fa4d7a2 implement Array.transpose 2017-11-17 12:39:34 +01:00
Yukihiro "Matz" Matsumoto 0c3ee0ba66 Add `Array#{permutation,combination}. 2017-10-20 10:38:58 +09:00
Christopher Aue c956e17c02 Replaced Array#each with while loop for performance reasons
Example benchmark:
$ time build/bench/bin/mruby -e "Array.new(2_000_000){ |i| i }.index{ |i| i == 1_999_999 }"

Before:
real    0m0.934s
user    0m0.922s
sys     0m0.003s

After:
real    0m0.590s
user    0m0.583s
sys     0m0.007s
2017-08-26 15:57:25 +02:00
Christopher Aue 6c9013e22b Removed unneeded block check in Array#uniq 2017-08-26 15:57:25 +02:00
Christopher Aue f3fb43c729 Reimplemented Array#flatten with #flatten! 2017-08-26 15:57:25 +02:00
Christopher Aue 3359b86ec7 Improved speed of enumeration methods 2017-07-30 13:19:31 +02:00
Christopher Aue a3bfd735a0 Added Array#bsearch_index 2017-07-28 23:51:49 +02:00
Christopher Aue 451574f142 Refactored Array#bsearch 2017-07-28 23:51:40 +02:00
Lukas Elmer f02694ecc7 Update documentation of fetch
The sentence `Negative values of +index+ count from the end of the array.` can be interpreted that it only holds if a block is given. Clarify it.
2016-11-02 19:45:43 +01:00
Yukihiro "Matz" Matsumoto daf83946bb add #dig to Array,Hash and Struct 2016-03-23 11:49:28 +09:00
takahashim 621487a0cd add {Array|Hash|String}.try_convert 2015-11-24 08:39:39 +09:00
Yukihiro "Matz" Matsumoto fafe86d364 Array#index to take block; fix #2968 close #2970 2015-10-01 22:35:06 +09:00
INOUE Yasuyuki 0d055559f1 Use #nil? instead of == nil. 2015-08-22 19:57:11 +09:00
Jun Hiroe 1aa885fae0 Delete unused variable in Array#delete_if 2014-05-03 01:41:41 +09:00
Nobuyoshi Nakada ab67c57f65 remove trailing spaces 2014-04-30 09:50:14 +09:00