diff options
| author | dearblue <[email protected]> | 2021-11-28 18:21:29 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-11-28 18:21:29 +0900 |
| commit | c4bca7cbb3eda883c7b09b6c0568a90fb8a85a5d (patch) | |
| tree | 48bb84aa1582cbf63332319509d7288bffa7b73f /mrbgems | |
| parent | e4d691778676f8cb284c91b8ca72b2dff41e2560 (diff) | |
| download | mruby-c4bca7cbb3eda883c7b09b6c0568a90fb8a85a5d.tar.gz mruby-c4bca7cbb3eda883c7b09b6c0568a90fb8a85a5d.zip | |
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)
```
Diffstat (limited to 'mrbgems')
| -rw-r--r-- | mrbgems/mruby-array-ext/mrblib/array.rb | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-proc-ext/mrblib/proc.rb | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-string-ext/mrblib/string.rb | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index f7576cbf7..d04c11e64 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -382,7 +382,7 @@ class Array def fill(arg0=nil, arg1=nil, arg2=nil, &block) if arg0.nil? && arg1.nil? && arg2.nil? && !block - raise ArgumentError, "wrong number of arguments (0 for 1..3)" + raise ArgumentError, "wrong number of arguments (given 0, expected 1..3)" end beg = len = 0 diff --git a/mrbgems/mruby-proc-ext/mrblib/proc.rb b/mrbgems/mruby-proc-ext/mrblib/proc.rb index 3be0afbbc..0c0df205e 100644 --- a/mrbgems/mruby-proc-ext/mrblib/proc.rb +++ b/mrbgems/mruby-proc-ext/mrblib/proc.rb @@ -21,7 +21,7 @@ class Proc self_arity = self.arity if (self_arity >= 0 && arity != self_arity) || (self_arity < 0 && abs[self_arity] > arity) - raise ArgumentError, "wrong number of arguments (#{arity} for #{abs[self_arity]})" + raise ArgumentError, "wrong number of arguments (given #{arity}, expected #{abs[self_arity]})" end end diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb index d485c51ef..d8fd120a0 100644 --- a/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -151,7 +151,7 @@ class String # def slice!(arg1, arg2=nil) raise FrozenError, "can't modify frozen String" if frozen? - raise "wrong number of arguments (for 1..2)" if arg1.nil? && arg2.nil? + raise ArgumentError, "wrong number of arguments (expected 1..2)" if arg1.nil? && arg2.nil? if !arg1.nil? && !arg2.nil? idx = arg1 |
