diff options
| author | Hiroshi Mimaki <[email protected]> | 2018-11-27 09:09:20 +0900 |
|---|---|---|
| committer | Hiroshi Mimaki <[email protected]> | 2018-11-27 09:09:20 +0900 |
| commit | e3ae0e4f2962418106875217adcd4f5971ce4689 (patch) | |
| tree | 3000278ca91d089918c3b6103aedcff71baed99d /doc | |
| parent | 0711c861ca939c73bed9d91601f6cc38bdf474ba (diff) | |
| parent | 26475d0a7897c25f8632b776014a19c3a6f6ecc2 (diff) | |
| download | mruby-e3ae0e4f2962418106875217adcd4f5971ce4689.tar.gz mruby-e3ae0e4f2962418106875217adcd4f5971ce4689.zip | |
Merge branch 'master' into stable
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/limitations.md | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/limitations.md b/doc/limitations.md index 92858cb1f..825435f01 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -219,7 +219,7 @@ $ ruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)' [[{"a"=>1}], {:b=>2}] ``` -#### mruby [] +#### mruby [mruby 2.0.0] ``` $ ./bin/mruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)' @@ -227,3 +227,23 @@ trace (most recent call last): [0] -e:1 -e:1: keyword argument hash with non symbol keys (ArgumentError) ``` + +## Argument Destructuring + +```ruby +def m(a,(b,c),d); p [a,b,c,d]; end +m(1,[2,3],4) # => [1,2,3,4] +``` +Destructured arguments (`b` and `c` in above example) cannot be accessed +from the default expression of optional arguments and keyword arguments, +since actual assignment is done after the evaluation of those default +expressions. Thus: + +```ruby +def f(a,(b,c),d=b) + p [a,b,c,d] +end +f(1,[2,3]) +``` + +CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`. |
