23件ヒット
[1-23件を表示]
(0.049秒)
別のキーワード
検索結果
-
NoMatchingPatternError (44000.0)
-
パターンマッチでどの条件にも一致せず、else節もない場合に発生します。
パターンマッチでどの条件にも一致せず、else節もない場合に発生します。 -
パターンマッチ (3006.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...パターンマッチ
* patterns
* variable_binding
* variable_pinning
* matching_non_primitive_objects
* guard_clauses
* current_feature_status
* pattern_syntax
* some_undefined_behavior_examples
パターンマッチは、構造化された値に対して、構造をチェック......ず else 節がない場合、例外 NoMatchingPatternError が発生します。
そのため、条件付きのマッチや展開に case 式が使われることがあります。
//emlist[][ruby]{
config = {db: {user: 'admin', password: 'abc123'}}
case config
in db: {user:} # ネストして......gnized structure of config"
end
# "Connect with user 'admin'" と出力
//}
一方、『in』 文は、期待されるデータ構造があらかじめ分かっている場合に、その一部を展開するのに有効です。
//emlist{
config = {db: {user: 'admin', password: 'abc123'}}
config......}'"
else
puts "Unrecognized structure of config"
end
# "Connect with user 'admin'" と出力
//}
一方、『=>』 演算子は、期待されるデータ構造があらかじめ分かっている場合に、その一部を展開するのに有効です。
//emlist{
config = {db: {user: 'admin',... -
NEWS for Ruby 3
. 0 . 0 (12.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...* Keyword arguments are now separated from positional arguments.
Code that resulted in deprecation warnings in Ruby 2.7 will now
result in ArgumentError or different behavior. 14183
* Procs accepting a single rest argument and keywords are no longer
subject to autosplatting. This now......accepting a single rest argument and no keywords.
16166
//emlist[][ruby]{
pr = proc{|*a, **kw| [a, kw]}
pr.call([1])
# 2.7 => [[1], {}]
# 3.0 => [[[1]], {}]
pr.call([1, {a: 1}])
# 2.7 => [[1], {:a=>1}] # and deprecation warning
# 3.0 => a=>1}, {}]
//}
* Arguments forwarding (`...`) now......t can be used like a rightward assignment.
17260
* `in` is changed to return `true` or `false`. 17371
//emlist{
0 => a
p a #=> 0
{b: 0, c: 1} => {b:}
p b #=> 0
//}
//emlist{
# version 3.0
0 in 1 #=> false
# version 2.7
0 in 1 #=> raise NoMatchingPatternError
//}
* Find-pattern...