From 3e4ce193432446c2a0610face701c2375ee8f0bd Mon Sep 17 00:00:00 2001 From: Fumiya Shibusawa Date: Tue, 7 Jan 2020 15:27:45 +0900 Subject: [PATCH 0001/1025] feat: add ja translation for community guideline page --- ja/conduct/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ja/conduct/index.md diff --git a/ja/conduct/index.md b/ja/conduct/index.md new file mode 100644 index 0000000000..05de7bfc5b --- /dev/null +++ b/ja/conduct/index.md @@ -0,0 +1,15 @@ +--- +layout: page +title: "Rubyコミュニティの行動規範ガイドライン" +lang: ja +--- + +Ruby開発者のコミュニティにおける安全かつ生産的なコラボレーションのため、以下の行動規範ガイドラインを用意しています。なお、これらはPostgreSQLの行動規範のドラフトを参考にしています。Rubyに関係するコミュニティ(カンファレンスなど)などで行動規範をつくる際にここから目的に沿うものを取っていただいて構いません。 +{: .summary} + +このドキュメントは、Rubyコミュニティに貢献したいと思うすべての人々にとって安全で生産的かつ協力的で互いに敬意を払える場所を提供するためのものです。コミュニティでコミュニケーションをする場(メーリングリスト、パッチの提出、commitのコメントなど)などすべてで適用されます。 + + * 参加者は、自身とは異なる意見、考えにも寛容な態度を示します。 + * 参加者は個人に対する攻撃や誹謗中傷などを示す発言・行動がないことを保証します。 + * 他の参加者の言葉や行動を解釈する際、それらが常に善意に基づくものだという前提に立ちます。 + * 合理的に考えてそれがハラスメントだとみなされる振る舞いは許容しません。 From 8ae349b56f7387677ab8b9c5183bebf4d02ea2cd Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:17 +0900 Subject: [PATCH 0002/1025] Add en doc --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md new file mode 100644 index 0000000000..44cd874cc1 --- /dev/null +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -0,0 +1,355 @@ +--- +layout: news_post +title: "Separation of positional and keyword arguments in Ruby 3.0" +author: "mame" +translator: +date: 2019-12-12 12:00:00 +0000 +lang: en +--- + +This article explains the planned incompatibility of keyword arguments in Ruby 3.0 + +## tl;dr + +In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: + +* `Using the last argument as keyword parameters is deprecated`, or +* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Splitting the last argument into positional and keyword parameters is deprecated` + +In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. + +In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. + +## Typical cases + +Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. + +{% highlight ruby %} +# This method accepts only a keyword argument +def foo(k: 1) + p k +end + +h = { k: 42 } + +# This method call passes a positional Hash argument +# In Ruby 2.7: The Hash is automatically converted to a keyword argument +# In Ruby 3.0: This call raises an ArgumentError +foo(h) + # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call + # demo.rb:2: warning: The called method `foo' is defined here + # 42 + +# If you want to keep the behavior in Ruby 3.0, use double splat +foo(**h) #=> 42 +{% endhighlight %} + +Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. + +{% highlight ruby %} +# This method accepts one positional argument and a keyword rest argument +def bar(h, **kwargs) + p h +end + +# This call passes only a keyword argument and no positional arguments +# In Ruby 2.7: The keyword is converted to a positional Hash argument +# In Ruby 3.0: This call raises an ArgumentError +bar(k: 42) + # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated + # demo2.rb:2: warning: The called method `bar' is defined here + # {:k=>42} + +# If you want to keep the behavior in Ruby 3.0, write braces to make it an +# explicit Hash +bar({ k: 42 }) # => {:k=>42} +{% endhighlight %} + +## What is deprecated? + +In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. + +Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. + +Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. + +{% highlight ruby %} +def foo(kwargs = {}) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. + +However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +## Will my code break on Ruby 2.7? + +A short answer is "maybe not". + +The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. + +Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. + +If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. + +## Handling argument delegation + +### Ruby 2.6 or prior + +In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. + +{% highlight ruby %} +def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +### Ruby 3 + +You need to explicitly delegate keyword arguments. + +{% highlight ruby %} +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end +{% endhighlight %} + +Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. + +{% highlight ruby %} +def foo(...) + target(...) +end +{% endhighlight %} + +### Ruby 2.7 + +In short: use `Module#ruby2_keywords` and delegate `*args, &block`. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. + +In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. + +### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 + +In short: use `Module#ruby2_keywords` again. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: + +{% highlight ruby %} +def ruby2_keywords(*) +end if RUBY_VERSION < "2.7" +{% endhighlight %} + +--- + +If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo({}) #=> Ruby 2.7: [] ({} is dropped) +foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +{% endhighlight %} + +An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. + +As noted in the last line, you can work around this issue by using `**{}`. + +If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) +`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). + +## Other minor changes + +There are three minor changes about keyword arguments in Ruby 2.7. + +### 1. Non-Symbol keys are allowed in keyword arguments + +In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end +foo("key" => 42) + #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments + #=> Ruby 2.7 or later: {"key"=>42} +{% endhighlight %} + +If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. + +{% highlight ruby %} +def bar(x=1, **kwargs) + p [x, kwargs] +end + +bar("key" => 42, :sym => 43) + #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] + #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] + +# Use braces to keep the behavior +bar({"key" => 42}, :sym => 43) + #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] +{% endhighlight %} + +Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. + +{% highlight ruby %} +def bar(x=1, sym: nil) + p [x, sym] +end + +bar("key" => 42, :sym => 43) +# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated +# warning: The called method `bar' is defined here +# Ruby 3.0: ArgumentError +{% endhighlight %} + +### 2. Double splat with an empty hash (`**{}`) passes no arguments + +In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. + +{% highlight ruby %} +def foo(*args) + args +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. + +In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. + +{% highlight ruby %} +def foo(x) + x +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: {} + #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated + # warning: The called method `foo' is defined here + #=> Ruby 3.0: ArgumentError: wrong number of arguments +{% endhighlight %} + +### 3. The no-keyword-arguments syntax (`**nil`) is introduced + +You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) + +{% highlight ruby %} +def foo(*args, **nil) +end + +foo(k: 1) + #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) +{% endhighlight %} + +This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: + +{% highlight ruby %} +# If a method accepts rest argument and no `**nil` +def foo(*args) + p args +end + +# Passing keywords are converted to a Hash object (even in Ruby 3.0) +foo(k: 1) #=> [{:k=>1}] + +# If the method is extended to accept a keyword +def foo(*args, mode: false) + p args +end + +# The existing call may break +foo(k: 1) #=> ArgumentError: unknown keyword k +{% endhighlight %} + +## Why we're deprecating the automatic conversion + +The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. + +Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. + +Here is one of the most confusing cases: + +{% highlight ruby %} +def foo(x, **kwargs) + p [x, kwargs] +end + +def bar(x=1, **kwargs) + p [x, kwargs] +end + +foo({}) => [{}, {}] +bar({}) => [1, {}] + +bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +{% endhighlight %} + +In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. + +You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. + +The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo() #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. + +The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. + +## Acknowledgment + +This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. + +## History + +* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. From a883bdda941814ffb08f6c1156453f8859655863 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:47 +0900 Subject: [PATCH 0003/1025] Translate "Separation of positional and keyword arguments in Ruby 3.0" --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 195 +++++++++--------- 1 file changed, 99 insertions(+), 96 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 44cd874cc1..5e80e231d5 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -2,77 +2,81 @@ layout: news_post title: "Separation of positional and keyword arguments in Ruby 3.0" author: "mame" -translator: +translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 -lang: en +lang: ja --- -This article explains the planned incompatibility of keyword arguments in Ruby 3.0 +本記事では、Ruby 3.0で予定されているキーワード引数の非互換性について解説します。 -## tl;dr +## 概要 -In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated`, or * `Passing the keyword argument as the last hash parameter is deprecated`, or * `Splitting the last argument into positional and keyword parameters is deprecated` -In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. +この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 -In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. +Ruby 3では、すべての引数を委譲するメソッドで、位置引数の他に必ずキーワード引数も明示的に委譲しなければなりません。Ruby 2.7以前の委譲の振る舞いを変えたくない場合は、`ruby2_keywords`をお使いください。詳しくは後述の「引数の委譲の扱いについて」をご覧ください。 -## Typical cases +## よくあるケース -Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. +以下はもっともよくあるケースです。Hashではなくキーワードを渡すのにdouble splat演算子(`**`)を使えます。 {% highlight ruby %} -# This method accepts only a keyword argument +# このメソッドはキーワード引数のみを受け取る def foo(k: 1) p k end h = { k: 42 } -# This method call passes a positional Hash argument -# In Ruby 2.7: The Hash is automatically converted to a keyword argument -# In Ruby 3.0: This call raises an ArgumentError +# このメソッド呼び出しは位置引数としてHashを渡している +# Ruby 2.7: このHashは自動でキーワード引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる foo(h) # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call # demo.rb:2: warning: The called method `foo' is defined here # 42 -# If you want to keep the behavior in Ruby 3.0, use double splat +# この振る舞いをRuby 3.0で変えたくない場合はdouble splatを用いる foo(**h) #=> 42 {% endhighlight %} -Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. +別の例: キーワード引数ではなくHashを明示的に渡す場合は中かっこ(`{}`)を使います。 {% highlight ruby %} -# This method accepts one positional argument and a keyword rest argument +# このメソッドは位置引数を1個、残りはキーワード引数を受け取る def bar(h, **kwargs) p h end -# This call passes only a keyword argument and no positional arguments -# In Ruby 2.7: The keyword is converted to a positional Hash argument -# In Ruby 3.0: This call raises an ArgumentError +# この呼び出しではキーワード引数のみが渡され、位置引数は渡されない +# Ruby 2.7: このキーワード引数は自動でHash引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる bar(k: 42) # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated # demo2.rb:2: warning: The called method `bar' is defined here # {:k=>42} -# If you want to keep the behavior in Ruby 3.0, write braces to make it an -# explicit Hash +# この振る舞いをRuby 3.0で変えたくない場合は +# 中かっこで明示的にHashにする bar({ k: 42 }) # => {:k=>42} {% endhighlight %} -## What is deprecated? +## どの動作が非推奨になるか -In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. +Ruby 2では、キーワード引数が末尾のハッシュ位置引数として扱われることがあります。また、末尾のハッシュ引数がキーワード引数として扱われることもあります。 -Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. +この自動変換は場合によっては複雑になりすぎてしまい、本記事末尾で後述するようにトラブルの原因になることがあります。そのため、この自動変換をRuby 2.7で非推奨とし、Ruby 3.0で廃止する予定です。言い換えると、Ruby 3.0のキーワード引数は位置引数と完全に分離されることになります。つまり、キーワード引数を渡したい場合は、常に`foo(k: expr)`または`foo(**expr)`の形にすべきです。(メソッド定義で)キーワード引数を受け取りたい場合は、原則として常に以下のいずれかの形にすべきです。 -Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. +* `def foo(k: default)` +* `def foo(k:)` +* `def foo(**kwargs)` + +なお、キーワード引数を受け取らないメソッドを呼び出すときにキーワード引数を渡した場合の振る舞いは、Ruby 3.0でも変わらない点にご注意ください。たとえば、以下のケースは非推奨にはならず、Ruby 3.0でも引き続き動作します(このキーワード引数は引き続きHash位置引数として扱われます)。 {% highlight ruby %} def foo(kwargs = {}) @@ -82,9 +86,9 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. +変わらない理由は、このスタイルが非常によく用いられていることと、この呼び出し方法では引数の扱いに曖昧な点がないためです。この振る舞いまで禁止してしまうと、得られるメリットが少ないうえに非互換性がさらに増えてしまいます。 -However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: +ただし今後新しいコードを書く場合、このスタイルはおすすめできません(Hashを位置引数として渡す頻度が高く、かつキーワード引数も使う場合を除く)。代わりに、次のようにdouble splat(`**`)をお使いください。 {% highlight ruby %} def foo(**kwargs) @@ -94,21 +98,21 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -## Will my code break on Ruby 2.7? +## Q: 自分のコードはRuby 2.7で動かなくなりますか? -A short answer is "maybe not". +手短かに言うと「壊れない可能性はあります」。 -The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. +Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 -Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. +Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. +非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 -## Handling argument delegation +## 引数の委譲の扱いについて -### Ruby 2.6 or prior +### Ruby 2.6以前の場合 -In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. +Ruby 2では、以下のように1個の`*rest`引数と1個の`&block`引数を受け付けて、この2つの引数を委譲先メソッド(以下の`target`)に渡すことで委譲メソッドを書けます。この振る舞いでは、(1つ以上の)キーワード引数も「位置引数<=>キーワード引数の自動変換」によって暗黙的に扱われます。 {% highlight ruby %} def foo(*args, &block) @@ -116,9 +120,9 @@ def foo(*args, &block) end {% endhighlight %} -### Ruby 3 +### Ruby 3の場合 -You need to explicitly delegate keyword arguments. +以下のようにキーワード引数を明示的に委譲する必要があります。 {% highlight ruby %} def foo(*args, **kwargs, &block) @@ -126,7 +130,7 @@ def foo(*args, **kwargs, &block) end {% endhighlight %} -Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. +別の方法として、Ruby 2.6以前との互換性を考慮する必要がなく、かつ引数を一切改変しないのであれば、以下のようにRuby 2.7で新しく導入される委譲構文(`...`)を利用できます。 {% highlight ruby %} def foo(...) @@ -134,9 +138,9 @@ def foo(...) end {% endhighlight %} -### Ruby 2.7 +### Ruby 2.7の場合 -In short: use `Module#ruby2_keywords` and delegate `*args, &block`. +手短かに言うと、以下のように`Module#ruby2_keywords`を用い、`*args, &block`を委譲します。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -144,13 +148,13 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. +`ruby2_keywords`を指定すると、キーワード引数を末尾のHash引数として受け取れるようになり、他のメソッドを呼び出すときにそれをキーワード引数として渡せます。 -In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. +実際、Ruby 2.7では多くの場面でこの新しい委譲のスタイルを利用できます。ただし1つ既知のエッジケースがあります。次をご覧ください。 -### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 +### Ruby 2.6 / 2.7 / 3で互換性のある委譲スタイル -In short: use `Module#ruby2_keywords` again. +手短かに言うと、ここも「`Module#ruby2_keywords`を使う」となります。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -158,16 +162,16 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) end if RUBY_VERSION < "2.7" {% endhighlight %} ---- +* * * * * -If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: +自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 {% highlight ruby %} def target(*args) @@ -178,35 +182,34 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo({}) #=> Ruby 2.7: [] ({} is dropped) -foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +foo({}) #=> Ruby 2.7: [] ({}を含んでいない) +foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 -As noted in the last line, you can work around this issue by using `**{}`. +上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) -`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 -## Other minor changes +## その他の微細な変更点 -There are three minor changes about keyword arguments in Ruby 2.7. +Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 -### 1. Non-Symbol keys are allowed in keyword arguments +### 1\. キーワード引数で非シンボルキーを利用できるようになった -In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. +Ruby 2.6以前のキーワード引数では、シンボル形式のキーしか利用できませんでした。Ruby 2.7のキーワード引数では、以下のようにシンボル形式でないキーを利用できるようになります。 {% highlight ruby %} def foo(**kwargs) kwargs end foo("key" => 42) - #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments - #=> Ruby 2.7 or later: {"key"=>42} + #=> Ruby 2.6以前: ArgumentError: wrong number of arguments + #=> Ruby 2.7以降: {"key"=>42} {% endhighlight %} -If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. +あるメソッドがオプション引数とキーワード引数を両方とも受け付ける場合、Ruby 2.6では以下のようにシンボル形式のキーと非シンボルキーを両方持つHashオブジェクトが2つに分割されていました。Ruby 2.7では非シンボルキーを利用できるので、どちらも受け取れます。 {% highlight ruby %} def bar(x=1, **kwargs) @@ -217,12 +220,12 @@ bar("key" => 42, :sym => 43) #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] -# Use braces to keep the behavior +# 振る舞いを変えたくない場合は中かっこ{}を使う bar({"key" => 42}, :sym => 43) #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] {% endhighlight %} -Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. +Ruby 2.7では、キーワード引数を明示的に受け付けるがキーワードrest引数(`**kwargs`)を受け取らないメソッドに対して、シンボル形式のキーと非シンボルキーが両方混じったHashやキーワード引数を渡すと、引き続きハッシュを分割して警告を表示します。この振る舞いはRuby 3で廃止されて`ArgumentError`にする予定です。 {% highlight ruby %} def bar(x=1, sym: nil) @@ -230,15 +233,15 @@ def bar(x=1, sym: nil) end bar("key" => 42, :sym => 43) -# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.6と2.7: => [{"key"=>42}, 43] # Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated # warning: The called method `bar' is defined here # Ruby 3.0: ArgumentError {% endhighlight %} -### 2. Double splat with an empty hash (`**{}`) passes no arguments +### 2\. double splatを付けた空ハッシュ(`**{}`)で引数を渡さないようになった -In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. +Ruby 2.6以前は、`**empty_hash`を渡すと位置引数に空のハッシュが渡されました(`[{}]`)。Ruby 2.7以降では引数を渡さなくなります。 {% highlight ruby %} def foo(*args) @@ -247,13 +250,13 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] + #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. +なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -262,51 +265,51 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: {} + #=> Ruby 2.6以前: {} #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated # warning: The called method `foo' is defined here #=> Ruby 3.0: ArgumentError: wrong number of arguments {% endhighlight %} -### 3. The no-keyword-arguments syntax (`**nil`) is introduced +### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 {% highlight ruby %} def foo(*args, **nil) end foo(k: 1) - #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) + #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} -# If a method accepts rest argument and no `**nil` +# メソッドは残りの引数を受け取るが、`**nil`はない状態 def foo(*args) p args end -# Passing keywords are converted to a Hash object (even in Ruby 3.0) +# キーワード引数はHashオブジェクトに変換される(Ruby 3.0でも同じ) foo(k: 1) #=> [{:k=>1}] -# If the method is extended to accept a keyword +# メソッドがキーワード引数を受け取るよう拡張した場合 def foo(*args, mode: false) p args end -# The existing call may break +# 以下の呼び出しが壊れる可能性がある foo(k: 1) #=> ArgumentError: unknown keyword k {% endhighlight %} -## Why we're deprecating the automatic conversion +## 自動変換を非推奨に変える理由 -The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. +当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. +自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 -Here is one of the most confusing cases: +最も混乱を呼ぶケースのひとつを以下に示します。 {% highlight ruby %} def foo(x, **kwargs) @@ -317,17 +320,17 @@ def bar(x=1, **kwargs) p [x, kwargs] end -foo({}) => [{}, {}] -bar({}) => [1, {}] +foo({}) #=> [{}, {}] +bar({}) #=> [1, {}] -bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +bar({}, **{}) #=> 期待は: [{}, {}]だが実際はl: [1, {}] {% endhighlight %} -In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. +Ruby 2の場合、`foo({})`は空のハッシュを通常の引数として1つ渡しますが(`x`に`{}`が代入されるなど)、`bar({})`はキーワード引数を1つ渡します(`kwargs`に`{}`が代入されるなど)。つまり、`any_method({})`は極めてあいまいになります。 -You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. +「`bar({}, **{})`は`x`に明示的に空のハッシュを渡すのでは?」と考える人もいるかもしれませんが、驚いたことに、この期待は裏切られます。Ruby 2.6では`[1, {}]`が出力されるのです。理由は、`**{}`がRuby 2.6のパーサーで無視されるのと、1番目の引数`{}`が自動的にキーワード引数(`**kwargs`)に変換されるためです。この場合`bar({}, {})`という形で呼び出す必要がありますが、これではあまりに見苦しくなります。 -The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. +同じ問題は、残りの引数とキーワード引数を受け取るメソッドにも当てはまります。そのせいで、以下のようなキーワード引数の明示的な委譲は動作しません。 {% highlight ruby %} def target(*args) @@ -338,18 +341,18 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo() #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] +foo() #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 -The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. +自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 -## Acknowledgment +## 謝辞 -This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. +本記事はJeremy EvansとBenoit Dalozeによる丁寧なレビュー(共著と言ってもよいくらいです)をいただきました。 -## History +## 更新履歴 -* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. +* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 From 14e04bc34672d0e27ba23212213843b764d3ad73 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Thu, 30 Jan 2020 16:49:40 +0900 Subject: [PATCH 0004/1025] Fix untranslated lines --- ...ation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 5e80e231d5..b9aec21a12 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -1,6 +1,6 @@ --- layout: news_post -title: "Separation of positional and keyword arguments in Ruby 3.0" +title: "Ruby 3.0における位置引数とキーワード引数の分離について" author: "mame" translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 @@ -13,8 +13,8 @@ lang: ja Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 -* `Using the last argument as keyword parameters is deprecated`, or -* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Using the last argument as keyword parameters is deprecated` +* `Passing the keyword argument as the last hash parameter is deprecated` * `Splitting the last argument into positional and keyword parameters is deprecated` この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 From 41d8abca5dfd1a2dbd578c47796740cd5cf7c24e Mon Sep 17 00:00:00 2001 From: vurtn Date: Tue, 26 Oct 2021 08:56:52 +0200 Subject: [PATCH 0005/1025] Translate from Jul to Aug 2021 (fr) --- .../_posts/2021-04-05-ruby-2-5-9-released.md | 2 +- .../_posts/2021-04-05-ruby-2-6-7-released.md | 4 +- .../_posts/2021-04-05-ruby-2-7-3-released.md | 2 +- .../_posts/2021-04-05-ruby-3-0-1-released.md | 2 +- ...ath-traversal-on-windows-cve-2021-28966.md | 4 +- ...p-vulnerability-in-rexml-cve-2021-28965.md | 4 +- ...2021-05-02-os-command-injection-in-rdoc.md | 2 +- .../_posts/2021-07-07-ruby-2-6-8-released.md | 59 +++++++++++++++++++ .../_posts/2021-07-07-ruby-2-7-4-released.md | 57 ++++++++++++++++++ .../_posts/2021-07-07-ruby-3-0-2-released.md | 48 +++++++++++++++ ...21-07-07-starttls-stripping-in-net-imap.md | 33 +++++++++++ ...7-07-trusting-pasv-responses-in-net-ftp.md | 33 +++++++++++ .../2021-08-03-fukuoka-ruby-award-2022.md | 32 ++++++++++ 13 files changed, 272 insertions(+), 10 deletions(-) create mode 100644 fr/news/_posts/2021-07-07-ruby-2-6-8-released.md create mode 100644 fr/news/_posts/2021-07-07-ruby-2-7-4-released.md create mode 100644 fr/news/_posts/2021-07-07-ruby-3-0-2-released.md create mode 100644 fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md create mode 100644 fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md create mode 100644 fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md diff --git a/fr/news/_posts/2021-04-05-ruby-2-5-9-released.md b/fr/news/_posts/2021-04-05-ruby-2-5-9-released.md index 945c6db0ec..f560198b7e 100644 --- a/fr/news/_posts/2021-04-05-ruby-2-5-9-released.md +++ b/fr/news/_posts/2021-04-05-ruby-2-5-9-released.md @@ -2,7 +2,7 @@ layout: news_post title: "Ruby 2.5.9 est disponible" author: "usa" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 lang: fr --- diff --git a/fr/news/_posts/2021-04-05-ruby-2-6-7-released.md b/fr/news/_posts/2021-04-05-ruby-2-6-7-released.md index 6c5d6f6659..b14bbaffb3 100644 --- a/fr/news/_posts/2021-04-05-ruby-2-6-7-released.md +++ b/fr/news/_posts/2021-04-05-ruby-2-6-7-released.md @@ -2,7 +2,7 @@ layout: news_post title: "Ruby 2.6.7 est disponible" author: "usa" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 lang: fr --- @@ -20,7 +20,7 @@ Voir les [logs de commit](https://github.com/ruby/ruby/compare/v2_6_6...v2_6_7) A partir de cette version, nous terminons la phase de maintenance standard de la branche 2.6 et entrons dans la phase de maintenance de sécurité. Cela signifie qu'il n'y aura plus de _backports_ de correctifs pour Ruby 2.6 sauf pour ceux concernant la sécurité. Cette phase de maintenance réduite se terminera dans un an. La branche 2.6 de Ruby ne sera alors plus officiellement supportée. -Nous vous recommandons donc passer vers Ruby 2.7 ou 3.0. +Nous vous recommandons donc de passer vers Ruby 2.7 ou 3.0. ## Téléchargement diff --git a/fr/news/_posts/2021-04-05-ruby-2-7-3-released.md b/fr/news/_posts/2021-04-05-ruby-2-7-3-released.md index 7ff88a2073..f02e19a499 100644 --- a/fr/news/_posts/2021-04-05-ruby-2-7-3-released.md +++ b/fr/news/_posts/2021-04-05-ruby-2-7-3-released.md @@ -2,7 +2,7 @@ layout: news_post title: "Ruby 2.7.3 est disponible" author: "nagachika" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 lang: fr --- diff --git a/fr/news/_posts/2021-04-05-ruby-3-0-1-released.md b/fr/news/_posts/2021-04-05-ruby-3-0-1-released.md index f0121a2917..9865d8d46d 100644 --- a/fr/news/_posts/2021-04-05-ruby-3-0-1-released.md +++ b/fr/news/_posts/2021-04-05-ruby-3-0-1-released.md @@ -2,7 +2,7 @@ layout: news_post title: "Ruby 3.0.1 est disponible" author: "naruse" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 lang: fr --- diff --git a/fr/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md b/fr/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md index e65cecd177..70ede1cf1b 100644 --- a/fr/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md +++ b/fr/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md @@ -2,7 +2,7 @@ layout: news_post title: "CVE-2021-28966: Path traversal dans Tempfile sur Windows" author: "mame" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 tags: security lang: fr @@ -23,7 +23,7 @@ Tous les utilisateurs qui possède une version concernée devraient faire la mis - Ruby 2.7.2 ou inférieure - Ruby 3.0.0 -## Crédits +## Remerciements Merci à [Bugdiscloseguys](https://hackerone.com/bugdiscloseguys) pour la découverte de ce problème. diff --git a/fr/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/fr/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md index 2f29eeeffb..f1b84c3db5 100644 --- a/fr/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md +++ b/fr/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -2,7 +2,7 @@ layout: news_post title: "CVE-2021-28965: Vulnérabilité XML round-trip dans REXML" author: "mame" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-04-05 12:00:00 +0000 tags: security lang: fr @@ -35,7 +35,7 @@ Si vous utilisez Ruby 2.5.8 ou inférieure : - Ruby 3.0.1 ou inférieure - REXML gem 3.2.4 ou inférieure -## Crédits +## Remerciements Merci à [Juho Nurminen](https://hackerone.com/jupenur) pour la découverte de ce problème. diff --git a/fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md b/fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md index 68fde7fa64..7a0e46f25c 100644 --- a/fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md +++ b/fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md @@ -2,7 +2,7 @@ layout: news_post title: "CVE-2021-31799: Faille d'injection de commandes dans RDoc" author: "aycabta" -translator: "Manaleak2d" +translator: "Kevin Rosaz" date: 2021-05-02 09:00:00 +0000 tags: security lang: fr diff --git a/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md b/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md new file mode 100644 index 0000000000..08eefc0918 --- /dev/null +++ b/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md @@ -0,0 +1,59 @@ +--- +layout: news_post +title: "Ruby 2.6.8 est disponible" +author: "usa" +translator: "Kevin Rosaz" +date: 2021-07-07 09:00:00 +0000 +lang: fr +--- +Ruby 2.6.8 est disponible. + +Cette version contient des correctifs concernant des problèmes de sécurité. +Merci de regarder les sujets suivants pour plus de détails. + +* [CVE-2021-31810: Une vulnérabilité concernant la confiance des réponses FTP PASV dans Net::FTP]({%link fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md %}) +* [CVE-2021-32066: Une vulnérabilité StartTLS stripping dans Net::IMAP]({%link fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md %}) +* [CVE-2021-31799: Faille d'injection de commandes dans RDoc]({%link fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md %}) + +En règle générale, nous ne mettons pas à jour Ruby 2.6 à l'exception des correctifs de sécurité. Néanmoins, cette version inclut également la résolution de bugs de régression et de build. +Voir les [logs de commit](https://github.com/ruby/ruby/compare/v2_6_7...v2_6_8) pour de plus amples informations. + +Ruby 2.6 est désormais dans la phase de maintenance de sécurité jusqu'à la fin mars 2022. +Après cette date, la maintenance de Ruby 2.6 sera terminée. +Nous vous recommandons donc de passer vers Ruby 2.7 ou 3.0. + +## Téléchargement + +{% assign release = site.data.releases | where: "version", "2.6.8" | first %} + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Commentaire de version + +Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. \ No newline at end of file diff --git a/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md b/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md new file mode 100644 index 0000000000..8f425a43ca --- /dev/null +++ b/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md @@ -0,0 +1,57 @@ +--- +layout: news_post +title: "Ruby 2.7.4 est disponible" +author: "usa" +translator: "Kevin Rosaz" +date: 2021-07-07 09:00:00 +0000 +lang: fr +--- + +Ruby 2.7.4 est disponible. + +Cette version contient des correctifs concernant des problèmes de sécurité. +Merci de regarder les sujets suivants pour plus de détails. + +* [CVE-2021-31810: Une vulnérabilité concernant la confiance des réponses FTP PASV dans Net::FTP]({%link fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md %}) +* [CVE-2021-32066: Une vulnérabilité StartTLS stripping dans Net::IMAP]({%link fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md %}) +* [CVE-2021-31799: Faille d'injection de commandes dans RDoc]({%link fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md %}) + +Voir les [logs de commit](https://github.com/ruby/ruby/compare/v2_7_3...v2_7_4) pour de plus amples informations. + +## Téléchargement + +{% assign release = site.data.releases | where: "version", "2.7.4" | first %} + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Commentaire de version + +Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. + +Le support de la branche 2.7 est documenté et encadré par le document *Agreement for the Ruby stable version* publié par la Ruby Association. \ No newline at end of file diff --git a/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md b/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md new file mode 100644 index 0000000000..5b4c46fa5e --- /dev/null +++ b/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md @@ -0,0 +1,48 @@ +--- +layout: news_post +title: "Ruby 3.0.2 est disponible" +author: "nagachika" +translator: "Kevin Rosaz" +date: 2021-07-07 09:00:00 +0000 +lang: fr +--- + +Ruby 3.0.2 est disponible. + +Cette version contient des correctifs concernant des problèmes de sécurité. +Merci de regarder les sujets suivants pour plus de détails. + +* [CVE-2021-31810: Une vulnérabilité concernant la confiance des réponses FTP PASV dans Net::FTP]({%link fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md %}) +* [CVE-2021-32066: Une vulnérabilité StartTLS stripping dans Net::IMAP]({%link fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md %}) +* [CVE-2021-31799: Faille d'injection de commandes dans RDoc]({%link fr/news/_posts/2021-05-02-os-command-injection-in-rdoc.md %}) + +Voir les [logs de commit](https://github.com/ruby/ruby/compare/v3_0_1...v3_0_2) pour de plus amples informations. + +## Téléchargement + +{% assign release = site.data.releases | where: "version", "3.0.2" | first %} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Commentaire de version + +Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. \ No newline at end of file diff --git a/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md new file mode 100644 index 0000000000..09bbe43b9f --- /dev/null +++ b/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -0,0 +1,33 @@ +--- +layout: news_post +title: "CVE-2021-32066: Une vulnérabilité StartTLS stripping dans Net::IMAP" +author: "shugo" +translator: "Kevin Rosaz" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: fr +--- + +Une vulnérabilité StartTLS stripping a été découverte dans Net::IMAP. +Cette vulnérabilité possède l'identifiant CVE [CVE-2021-32066](https://nvd.nist.gov/vuln/detail/CVE-2021-32066). +Nous vous recommandons fortement de mettre à jour Ruby. + +net-imap est une gemme incluse par défaut dans Ruby 3.0.1, mais a un problème d'empaquetage. Veuillez donc mettre à jour Ruby lui-même. + +## Détails + +Net::IMAP ne lève pas d'exception lorsque StartTLS échoue avec une réponse inconnue. Cela pourrait permettre à des attaques de type man-in-the-middle de contourner les protections de TLS en se positionnant entre le client et le registre pour bloquer la commande StartTLS, alias une attaque par "StartTLS stripping". + +## Versions concernées + +* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 +* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 +* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 + +## Remerciements + +Merci à [Alexandr Savca](https://hackerone.com/chinarulezzz) pour la découverte de ce problème. + +## Historique + +* Paru initialement le 2021-07-07 09:00:00 UTC diff --git a/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md b/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md new file mode 100644 index 0000000000..fa2af0a512 --- /dev/null +++ b/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md @@ -0,0 +1,33 @@ +--- +layout: news_post +title: "CVE-2021-31810: Une vulnérabilité concernant la confiance des réponses FTP PASV dans Net::FTP" +author: "shugo" +translator: "Kevin Rosaz" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: fr +--- + +Une vulnérabilité concernant la confiance des réponses FTP PASV a été découverte dans Net::FTP. +Cette vulnérabilité possède l'identifiant CVE [CVE-2021-31810](https://nvd.nist.gov/vuln/detail/CVE-2021-31810). +Nous vous recommandons fortement de mettre à jour Ruby. + +net-ftp est une gemme incluse par défaut dans Ruby 3.0.1, mais a un problème d'empaquetage. Veuillez donc mettre à jour Ruby lui-même. + +## Détails + +Un serveur FTP malveillant peut utiliser la réponse PASV pour tromper Net::FTP afin qu'il se reconnecte à une adresse IP et port donnés. Cela permet potentiellement à Net::FTP de récupérer des informations sur des services qui sont par ailleurs privés et non divulgués (par exemple, l'attaquant peut effectuer des analyses de ports et récupérer les bannières de services). + +## Versions concernées + +* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 +* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 +* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 + +## Remerciements + +Merci à [Alexandr Savca](https://hackerone.com/chinarulezzz) pour la découverte de ce problème. + +## Historique + +* Paru initialement le 2021-07-07 09:00:00 UTC diff --git a/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md b/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md new file mode 100644 index 0000000000..0fa8054067 --- /dev/null +++ b/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md @@ -0,0 +1,32 @@ +--- +layout: news_post +title: "Concours 2022 Fukuoka Ruby Award - Les candidatures seront jugées par Matz" +author: "Fukuoka Ruby" +translator: "Kevin Rosaz" +date: 2021-08-03 00:00:00 +0000 +lang: fr +--- + +Chers passionnés de Ruby, + +Le gouvernement de Fukuoka au Japon et « Matz » Matsumoto aimeraient vous inviter à participer au concours Ruby suivant. Si vous avez développé un programme Ruby intéressant, vous êtes encouragés à postuler. + +Concours 2022 Fukuoka Ruby Award - Grand Prix - 1 Million de Yens! + +Date limite d'inscription : 3 décembre 2021 + +![Fukuoka Ruby Award](https://www.digitalfukuoka.jp/javascripts/kcfinder/upload/images/fukuokarubyaward2017.png) + +Matz et un groupe de panélistes sélectionneront les gagnants du concours de Fukuoka. Le grand prix du concours de Fukuoka est de 1 million de yens. Les anciens gagnants du grand prix sont Rhomobile (États-Unis) et APEC Climate Center (Corée). + +Les programmes inscrits au concours n'ont pas à être entièrement écrits en Ruby, mais doivent tirer parti des caractéristiques uniques de Ruby. + +Le programme doit avoir été développé ou mis à jour au cours de l'année passée. Veuillez visiter le site Web de Fukuoka suivant pour participer. + +[http://www.digitalfukuoka.jp/events/242](http://www.digitalfukuoka.jp/events/242) + +Veuillez envoyer le formulaire de candidature à award@f-ruby.com + +« Matz testera et révisera votre code source de manière approfondie, il est donc très intéressant de postuler ! Le concours est gratuit. » + +Merci! \ No newline at end of file From 45b03a82f61eb00c95ad1fe30395957d96605e7e Mon Sep 17 00:00:00 2001 From: vurtn Date: Tue, 26 Oct 2021 09:17:50 +0200 Subject: [PATCH 0006/1025] remove trailing whitespace and add newline at end of files --- fr/news/_posts/2021-07-07-ruby-2-6-8-released.md | 2 +- fr/news/_posts/2021-07-07-ruby-2-7-4-released.md | 2 +- fr/news/_posts/2021-07-07-ruby-3-0-2-released.md | 2 +- fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md | 6 +++--- .../_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md | 6 +++--- fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md b/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md index 08eefc0918..d798a9db12 100644 --- a/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md +++ b/fr/news/_posts/2021-07-07-ruby-2-6-8-released.md @@ -56,4 +56,4 @@ Nous vous recommandons donc de passer vers Ruby 2.7 ou 3.0. ## Commentaire de version -Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. \ No newline at end of file +Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. diff --git a/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md b/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md index 8f425a43ca..2f06161b78 100644 --- a/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md +++ b/fr/news/_posts/2021-07-07-ruby-2-7-4-released.md @@ -54,4 +54,4 @@ Voir les [logs de commit](https://github.com/ruby/ruby/compare/v2_7_3...v2_7_4) Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. -Le support de la branche 2.7 est documenté et encadré par le document *Agreement for the Ruby stable version* publié par la Ruby Association. \ No newline at end of file +Le support de la branche 2.7 est documenté et encadré par le document *Agreement for the Ruby stable version* publié par la Ruby Association. diff --git a/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md b/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md index 5b4c46fa5e..b6753fc1d4 100644 --- a/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md +++ b/fr/news/_posts/2021-07-07-ruby-3-0-2-released.md @@ -45,4 +45,4 @@ Voir les [logs de commit](https://github.com/ruby/ruby/compare/v3_0_1...v3_0_2) ## Commentaire de version -Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. \ No newline at end of file +Merci aux contributeurs, développeurs et utilisateurs qui, en reportant les bugs, nous ont permis de faire cette version. diff --git a/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md index 09bbe43b9f..8574b3db89 100644 --- a/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md +++ b/fr/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -20,9 +20,9 @@ Net::IMAP ne lève pas d'exception lorsque StartTLS échoue avec une réponse in ## Versions concernées -* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 -* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 -* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 +* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 +* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 +* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 ## Remerciements diff --git a/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md b/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md index fa2af0a512..4e3d446bf8 100644 --- a/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md +++ b/fr/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md @@ -20,9 +20,9 @@ Un serveur FTP malveillant peut utiliser la réponse PASV pour tromper Net::FTP ## Versions concernées -* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 -* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 -* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 +* Toutes les versions de Ruby 2.6 antérieures à Ruby 2.6.7 +* Toutes les versions de Ruby 2.7 antérieures à Ruby 2.7.3 +* Toutes les versions de Ruby 3.0 antérieures à Ruby 3.0.1 ## Remerciements diff --git a/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md b/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md index 0fa8054067..5cfd9c11f3 100644 --- a/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md +++ b/fr/news/_posts/2021-08-03-fukuoka-ruby-award-2022.md @@ -11,7 +11,7 @@ Chers passionnés de Ruby, Le gouvernement de Fukuoka au Japon et « Matz » Matsumoto aimeraient vous inviter à participer au concours Ruby suivant. Si vous avez développé un programme Ruby intéressant, vous êtes encouragés à postuler. -Concours 2022 Fukuoka Ruby Award - Grand Prix - 1 Million de Yens! +Concours 2022 Fukuoka Ruby Award - Grand Prix - 1 Million de Yens ! Date limite d'inscription : 3 décembre 2021 @@ -29,4 +29,4 @@ Veuillez envoyer le formulaire de candidature à award@f-ruby.com « Matz testera et révisera votre code source de manière approfondie, il est donc très intéressant de postuler ! Le concours est gratuit. » -Merci! \ No newline at end of file +Merci ! From e2e070d129859841d20938e2389ee48bfc8c4724 Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Sun, 31 Oct 2021 21:26:36 +0100 Subject: [PATCH 0007/1025] Remove Google Analytics --- _includes/analytics.html | 13 ------------- _layouts/default.html | 2 -- 2 files changed, 15 deletions(-) delete mode 100644 _includes/analytics.html diff --git a/_includes/analytics.html b/_includes/analytics.html deleted file mode 100644 index a7857b1cb9..0000000000 --- a/_includes/analytics.html +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/_layouts/default.html b/_layouts/default.html index 1dcd676b34..e963a7ce7a 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -78,7 +78,5 @@

{{ site.data.locales[page.lang].slogan }}

{% include credits.html %} - - {% include analytics.html %} From 16c3252e6cf2144eafc605d573d76a36740b6a15 Mon Sep 17 00:00:00 2001 From: Alexander Ilyin Date: Tue, 2 Nov 2021 23:17:00 +0300 Subject: [PATCH 0008/1025] Prepare ru locale maintained (ru) - set locale to admin/translation-status page - do redirect to locale from /index.html - see #2721 for more details --- _plugins/translation_status.rb | 2 +- index.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/_plugins/translation_status.rb b/_plugins/translation_status.rb index 65732e316b..0e7d1d53d8 100644 --- a/_plugins/translation_status.rb +++ b/_plugins/translation_status.rb @@ -8,7 +8,7 @@ module Jekyll # Outputs HTML. module TranslationStatus - LANGS = %w[en de es id ja ko pt tr zh_cn zh_tw].freeze + LANGS = %w[en de es id ja ko pt ru tr zh_cn zh_tw].freeze START_DATE = "2013-04-01" OK_CHAR = "✓" diff --git a/index.html b/index.html index a3024b2082..ee0dfd348b 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,7 @@ "ja": "ja", "ko": "ko", "pt": "pt", + "ru": "ru", "tr": "tr", "zh-CN": "zh_cn", "zh-TW": "zh_tw" From 2ce5cd6c8a72592c8e36340ced264ed66e9acc3b Mon Sep 17 00:00:00 2001 From: vurtn Date: Thu, 11 Nov 2021 21:28:10 +0100 Subject: [PATCH 0009/1025] translation of ruby 3.1.0 preview1 (fr) --- ...2021-11-09-ruby-3-1-0-preview1-released.md | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 fr/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md diff --git a/fr/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md b/fr/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md new file mode 100644 index 0000000000..d80e6c8737 --- /dev/null +++ b/fr/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md @@ -0,0 +1,215 @@ +--- +layout: news_post +title: "Ruby 3.1.0 Preview 1 est disponible" +author: "naruse" +translator: "Kevin Rosaz" +date: 2021-11-09 00:00:00 +0000 +lang: fr +--- +{% assign release = site.data.releases | where: "version", "3.1.0-preview1" | first %} + +Nous avons le plaisir de vous annoncer la sortie de Ruby {{ release.version }}. + + +## YJIT: un nouveau compilateur JIT en cours de développement + + +Ruby 3.1 fusionne YJIT, un nouveau compilateur JIT développé par Shopify. + +Depuis que [Ruby 2.6 a introduit MJIT en 2018](https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/), ses performances se sont grandement améliorées et [nous sommes parvenus à Ruby3x3 l'année dernière](https://www.ruby-lang.org/fr/news/2020/12/25/ruby-3-0-0-released/). Même si Optcarrot a montré des accélérations impressionnantes, le JIT n'a pas profité aux applications du monde professionnel. + +Récemment, Shopify a apporté de nombreuses améliorations à Ruby pour accélérer son application Rails. YJIT est une contribution importante et vise à améliorer les performances des applications Rails. + +Bien que MJIT soit un compilateur JIT basé sur des méthodes et qu'il utilise un compilateur C externe, YJIT utilise le Basic Block Versioning et inclut le compilateur JIT à l'intérieur. Avec Lazy Basic Block Versioning (LBBV), cela compile d'abord le début d'une méthode et compile progressivement le reste lorsque le type des arguments et des variables est déterminé dynamiquement. Voir [YJIT: a basic block versioning JIT compiler for CRuby](https://dl.acm.org/doi/10.1145/3486606.3486781) pour une introduction détaillée. + +Avec cette technologie, YJIT permet d'avoir à la fois un temps de démarrage rapide et des améliorations de performance sur la plupart des logiciels, jusqu'à 22% sur railsbench et 39% sur le rendu liquid. + + + +YJIT est toujours une fonctionnalité expérimentale. En tant que telle, elle est désactivée par défaut. Si vous souhaitez l'utiliser, spécifiez l'option en ligne de commande `--yjit` pour activer YJIT. L'utilisation est pour le moment limitée à macOS et Linux sur les plateformes x86-64. + +* https://bugs.ruby-lang.org/issues/18229 +* https://shopify.engineering/yjit-just-in-time-compiler-cruby +* https://www.youtube.com/watch?v=PBVLf3yfMs8 + +## debug gem: un nouveau débogueur + +Un nouveau débogueur [debug.gem](https://github.com/ruby/debug) est inclu. debug.gem est une implémentation rapide du débogueur et fournit de nombreuses fonctionnalités telles que le débogage à distance, un REPL coloré, une intégration dans un IDE (VSCode) et bien plus encore. Cela remplace `lib/debug.rb` de la bibliothèque standard. + +## error_highlight: localisation des erreurs plus précise + +La gemme error_highlight a été ajoutée. Elle permet d'obtenir la localisation d'une erreur de manière plus précise dans la trace : + +``` +$ ruby test.rb +test.rb:1:in `
': undefined method `time' for 1:Integer (NoMethodError) + +1.time {} + ^^^^^ +Did you mean? times +``` + +Cette gemme est activée par défaut. Vous pouvez la désactiver en utilisant l'option en ligne de commande `--disable-error_highlight`. Voir [le dépôt](https://github.com/ruby/error_highlight) pour de plus amples informations. + +## Amélioration d'IRB + +À décrire dans le prochain aperçu. + +## Autres nouvelles fonctionnalités notables + +### Language + +* Les valeurs dans les littéraux de hachage peuvent être omis. [Feature #14579] + * `{x:, y:}` est un sucre syntaxique de `{x: x, y: y}`. + * `foo(x:, y:)` est un sucre syntaxique de `foo(x: x, y: y)`. + +* L'opérateur pin dans le filtrage par motif prend désormais une expression. [Feature #17411] + +```ruby +Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a +#=> [[3, 5], [5, 7], [11, 13]] +``` + + +### RBS + +RBS est un langage pour décrire la structure des programmes Ruby. Voir [le dépôt](https://github.com/ruby/rbs) pour de plus amples informations. + +Mises à jour depuis Ruby 3.0.0: + +* `rbs collection` a été introduite pour gérer les RBS des gemmes. [doc](https://github.com/ruby/rbs/blob/master/docs/collection.md) +* Plusieurs signatures pour des bibliothèques intégrées et standards ont été ajoutées/mises à jour. +* Il y a également de nombreuses corrections de bogues et d'améliorations de performance. + +Voir [le CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md) pour de plus amples informations. + +### TypeProf + +TypeProf est un analyseur de type statique pour Ruby. Il génère un prototype de RBS à partir de code Ruby non annoté de type. Voir [le document](https://github.com/ruby/typeprof/blob/master/doc/doc.md) pour de plus amples informations. + +Mises à jour depuis Ruby 3.0.0 : + +* [Le support expérimental pour IDE](https://github.com/ruby/typeprof/blob/master/doc/ide.md) a été implémenté. +* Il y a également de nombreuses corrections de bogues et d'améliorations de performance. + +## Amélioration de performance + +* MJIT + * Pour les charges de travail telles que Rails, la valeur par défaut `--jit-max-cache` passe de 100 à 10000. + Le compilateur JIT ne saute plus la compilation des méthodes de plus de 1000 instructions. + * Pour prendre en charge Zeitwerk de Rails, le code généré par le compilateur JIT n'est plus annulé + lorsqu'un TracePoint est activé pour les évènements de classe. + +## Autres changements notables depuis la version 3.0 + +* Le filtrage par motif en une ligne, e.g., `ary => [x, y, z]`, n'est plus au stade expérimental. +* L'ordre d'évaluation des affectations multiples a été légèrement modifié. [[Bug #4443]](https://bugs.ruby-lang.org/issues/4443) + * `foo[0], bar[0] = baz, qux` était évalué dans l'ordre `baz`, `qux`, `foo` puis `bar` dans Ruby 3.0. Dans Ruby 3.1, l'évaluation est dans l'ordre `foo`, `bar`, `baz` puis `qux`. +* Allocation de la taille d'une variable: Strings (expérimental) [[Bug #18239]](https://bugs.ruby-lang.org/issues/18239) + +### Mises à jour des bibliothèques standards + +* Plusieurs bibliothèques standards ont été mises à jour. + * RubyGems + * Bundler + * RDoc 6.4.0 + * ReLine + * JSON 2.6.0 + * Psych 4.0.2 + * FileUtils 1.6.0 + * Fiddle + * StringIO 3.0.1 + * IO::Console 0.5.9 + * IO::Wait 0.2.0 + * CSV + * Etc 1.3.0 + * Date 3.2.0 + * Zlib 2.1.1 + * StringScanner + * IpAddr + * Logger 1.4.4 + * OStruct 0.5.0 + * Irb + * Racc 1.6.0 + * Delegate 0.2.0 + * Benchmark 0.2.0 + * CGI 0.3.0 + * Readline(C-ext) 0.1.3 + * Timeout 0.2.0 + * YAML 0.2.0 + * URI 0.11.0 + * OpenSSL + * DidYouMean + * Weakref 0.1.1 + * Tempfile 0.1.2 + * TmpDir 0.1.2 + * English 0.7.1 + * Net::Protocol 0.1.2 + * Net::Http 0.2.0 + * BigDecimal + * OptionParser 0.2.0 + * Set + * Find 0.1.1 + * Rinda 0.1.1 + * Erb + * NKF 0.1.1 + * Base64 0.1.1 + * OpenUri 0.2.0 + * SecureRandom 0.1.1 + * Resolv 0.2.1 + * Resolv::Replace 0.1.0 + * Time 0.2.0 + * PP 0.2.1 + * Prettyprint 0.1.1 + * Drb 2.1.0 + * Pathname 0.2.0 + * Digest 3.1.0.pre2 + * Un 0.2.0 +* Les gemmes incluses suivantes ont été mises à jour. + * minitest 5.14.4 + * power_assert 2.0.1 + * rake 13.0.6 + * test-unit 3.5.0 + * rbs 1.6.2 + * typeprof 0.20.0 +* Les gemmes par défaut suivantes sont désormais incluses. + * net-ftp + * net-imap + * net-pop + * net-smtp + * matrix + * prime + +Voir [NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md) +ou les [logs de commit](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}) +pour de plus amples informations. + +Avec ces changements, [{{ release.stats.files_changed }} fichiers changés, {{ release.stats.insertions }} insertions(+), {{ release.stats.deletions }} suppressions(-)](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}#file_bucket) +depuis Ruby 3.0.0! + +## Téléchargement + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Ruby, c'est quoi ? + +Ruby a été initialement développé par Matz (Yukihiro Matsumoto) en 1993 puis est devenu open source. Il fonctionne sur de nombreuses plateformes et est utilisé partout dans le monde, en particulier pour le développement web. From fca1542763449250261863927fe1e455e7ca63c1 Mon Sep 17 00:00:00 2001 From: ytjmt <46666464+ytjmt@users.noreply.github.com> Date: Wed, 17 Nov 2021 00:21:45 +0900 Subject: [PATCH 0010/1025] Translate "CVE-2021-41817: Regular Expression Denial of Service Vulnerability of Date Parsing Methods" (ja) --- ...arsing-method-regexp-dos-cve-2021-41817.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ja/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md diff --git a/ja/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md b/ja/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md new file mode 100644 index 0000000000..87f5fd3cfa --- /dev/null +++ b/ja/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md @@ -0,0 +1,34 @@ +--- +layout: news_post +title: "CVE-2021-41817: 日付をパースするメソッドにおける正規表現 Denial of Service の脆弱性について" +author: "mame" +translator: "ytjmt" +date: 2021-11-15 08:00:00 +0000 +tags: security +lang: ja +--- + +日付をパースするメソッドにおける正規表現 Denial of Service(ReDoS)脆弱性の修正を含む、date gem 3.2.1、3.1.2、3.0.2、2.0.1 をリリースしました。攻撃者はこの脆弱性を悪用し、効果的な DoS 攻撃を引き起こすことができます。 + +## 詳細 + +`Date.parse` を含む、日付をパースするメソッドの内部では正規表現を利用しており、これらには ReDoS 攻撃に対して脆弱なものがあります。信頼できない入力値に対してこれらのメソッドを適用しているアプリケーションおよびライブラリはこの脆弱性の影響を受ける可能性があります。 + +この修正では、正規表現を変更するのではなく、入力値をデフォルトで 128 バイトまでに制限するようにしています。date gem は多くの正規表現を利用しており、脆弱性のある正規表現が他にも潜んでいる可能性があるためです。互換性のため、`Date.parse(str, limit: nil)` のように、`limit` に `nil` を明示的に渡すことでこの制限を除外することができますが、パースに時間がかかる可能性があることに留意してください。 + +date gem を 3.2.1、3.1.2、3.0.2、2.0.1 かそれ以降のバージョンにアップデートしてください。`gem update date` でアップデートできます。もし bundler を使っている場合は、`Gemfile` に `gem "date", ">= 3.2.1"` を追加してください。 + +## 影響を受けるバージョン + +* date gem 2.0.0 およびそれ以前のバージョン(Ruby 2.6 系列にバンドルされているバージョン) +* date gem 3.0.1 およびそれ以前のバージョン(Ruby 2.7 系列にバンドルされているバージョン) +* date gem 3.1.1 およびそれ以前のバージョン(Ruby 3.0 系列にバンドルされているバージョン) +* date gem 3.2.0 およびそれ以前のバージョン + +## クレジット + +この脆弱性情報は、[svalkanov](https://github.com/SValkanov/) 氏によって報告されました。 + +## 更新履歴 + +* 2021-11-15 17:00:00 (JST) 初版 From 9c7a4efab47960ddbbf17df91090b941f4fd2214 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 16:10:04 +0900 Subject: [PATCH 0011/1025] Fixed a command `gem upgrade rexml` -> `gem update rexml` --- ...4-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md index f4b0a0acf7..b6225aa9cc 100644 --- a/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md +++ b/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -29,7 +29,7 @@ If you are using Ruby 2.5.8 or prior: ## Affected versions -* Ruby 2.5.8 or prior (You can NOT use `gem upgrade rexml` for this version.) +* Ruby 2.5.8 or prior (You can NOT use `gem update rexml` for this version.) * Ruby 2.6.6 or prior * Ruby 2.7.2 or prior * Ruby 3.0.0 From af0e7e8562e60de55cd8fb9c3862a0f99d2e0f8c Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 21:21:41 +0900 Subject: [PATCH 0012/1025] Fixed a bug. Fixed a bug that disturbed XXX from being displayed. --- en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md b/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md index 7904833062..3afcf4a576 100644 --- a/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md +++ b/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md @@ -7,10 +7,9 @@ date: 2021-11-09 00:00:00 +0000 lang: en --- -We are pleased to announce the release of Ruby {{ release.version }}. - {% assign release = site.data.releases | where: "version", "3.1.0-preview1" | first %} +We are pleased to announce the release of Ruby {{ release.version }}. ## YJIT: New experimental in-process JIT compiler From 879ed2088c32fa8d6cd69712d99993124bb168bf Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 27 Nov 2021 00:48:28 +0900 Subject: [PATCH 0013/1025] Revised the points pointed out in the review. --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index b9aec21a12..38c2aea1c9 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -11,7 +11,9 @@ lang: ja ## 概要 -Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 +この文書では便宜上、必須引数、オプション引数、rest引数、後置引数(つまり、キーワード引数とブロック引数以外の引数)をまとめて「位置引数」と呼びます。 + +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7で警告を表示します。以下のいずれかの警告が表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated` * `Passing the keyword argument as the last hash parameter is deprecated` @@ -100,13 +102,13 @@ foo(k: 1) #=> {:k=>1} ## Q: 自分のコードはRuby 2.7で動かなくなりますか? -手短かに言うと「壊れない可能性はあります」。 +A: たぶん動きます。 -Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 +Ruby 2.7では、原則として、Ruby 3.0で変更される振る舞いについて警告を出すにとどめています。しかし、私たちが軽微とみなした非互換も少しだけ入っています。詳しくは後述の「その他の軽微な変更点」をご覧ください。 -Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 +Ruby 2.7では、警告が表示される点と軽微な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、警告が表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 +非推奨の警告を無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 ## 引数の委譲の扱いについて @@ -162,7 +164,7 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(つまり、**kwargsを受け渡ししないスタイル)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) @@ -186,15 +188,15 @@ foo({}) #=> Ruby 2.7: [] ({}を含んでいない) foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`target`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6がサポート切れになったあとで削除される可能性があります。そのときになったら、キーワード引数を明示的に委譲することをおすすめします(上述のRuby 3向けのコードを参照)。 -## その他の微細な変更点 +## その他の軽微な変更点 -Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 +Ruby 2.7のキーワード引数では、この他に以下の3つの軽微な変更が行われています。 ### 1\. キーワード引数で非シンボルキーを利用できるようになった @@ -256,7 +258,7 @@ foo(**empty_hash) なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡して警告を表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -273,7 +275,7 @@ foo(**empty_hash) ### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、新機能です)。 {% highlight ruby %} def foo(*args, **nil) @@ -283,7 +285,7 @@ foo(k: 1) #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例のrest引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} # メソッドは残りの引数を受け取るが、`**nil`はない状態 @@ -307,7 +309,7 @@ foo(k: 1) #=> ArgumentError: unknown keyword k 当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 +自動変換は、オプション引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 最も混乱を呼ぶケースのひとつを以下に示します。 @@ -345,7 +347,7 @@ foo() #=> Ruby 2.6以前: [{}] #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになり、blockはnilになります。。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 @@ -355,4 +357,4 @@ foo() #=> Ruby 2.6以前: [{}] ## 更新履歴 -* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 +* 更新 2019-12-25: 2.7.0-rc2で警告メッセージが若干変更され、警告抑制APIが追加された。 From 6d63b42335fa7eb881aa16c65d0b5f1756f0e269 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:17 +0900 Subject: [PATCH 0014/1025] Add en doc --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md new file mode 100644 index 0000000000..44cd874cc1 --- /dev/null +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -0,0 +1,355 @@ +--- +layout: news_post +title: "Separation of positional and keyword arguments in Ruby 3.0" +author: "mame" +translator: +date: 2019-12-12 12:00:00 +0000 +lang: en +--- + +This article explains the planned incompatibility of keyword arguments in Ruby 3.0 + +## tl;dr + +In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: + +* `Using the last argument as keyword parameters is deprecated`, or +* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Splitting the last argument into positional and keyword parameters is deprecated` + +In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. + +In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. + +## Typical cases + +Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. + +{% highlight ruby %} +# This method accepts only a keyword argument +def foo(k: 1) + p k +end + +h = { k: 42 } + +# This method call passes a positional Hash argument +# In Ruby 2.7: The Hash is automatically converted to a keyword argument +# In Ruby 3.0: This call raises an ArgumentError +foo(h) + # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call + # demo.rb:2: warning: The called method `foo' is defined here + # 42 + +# If you want to keep the behavior in Ruby 3.0, use double splat +foo(**h) #=> 42 +{% endhighlight %} + +Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. + +{% highlight ruby %} +# This method accepts one positional argument and a keyword rest argument +def bar(h, **kwargs) + p h +end + +# This call passes only a keyword argument and no positional arguments +# In Ruby 2.7: The keyword is converted to a positional Hash argument +# In Ruby 3.0: This call raises an ArgumentError +bar(k: 42) + # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated + # demo2.rb:2: warning: The called method `bar' is defined here + # {:k=>42} + +# If you want to keep the behavior in Ruby 3.0, write braces to make it an +# explicit Hash +bar({ k: 42 }) # => {:k=>42} +{% endhighlight %} + +## What is deprecated? + +In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. + +Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. + +Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. + +{% highlight ruby %} +def foo(kwargs = {}) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. + +However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +## Will my code break on Ruby 2.7? + +A short answer is "maybe not". + +The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. + +Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. + +If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. + +## Handling argument delegation + +### Ruby 2.6 or prior + +In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. + +{% highlight ruby %} +def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +### Ruby 3 + +You need to explicitly delegate keyword arguments. + +{% highlight ruby %} +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end +{% endhighlight %} + +Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. + +{% highlight ruby %} +def foo(...) + target(...) +end +{% endhighlight %} + +### Ruby 2.7 + +In short: use `Module#ruby2_keywords` and delegate `*args, &block`. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. + +In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. + +### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 + +In short: use `Module#ruby2_keywords` again. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: + +{% highlight ruby %} +def ruby2_keywords(*) +end if RUBY_VERSION < "2.7" +{% endhighlight %} + +--- + +If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo({}) #=> Ruby 2.7: [] ({} is dropped) +foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +{% endhighlight %} + +An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. + +As noted in the last line, you can work around this issue by using `**{}`. + +If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) +`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). + +## Other minor changes + +There are three minor changes about keyword arguments in Ruby 2.7. + +### 1. Non-Symbol keys are allowed in keyword arguments + +In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end +foo("key" => 42) + #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments + #=> Ruby 2.7 or later: {"key"=>42} +{% endhighlight %} + +If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. + +{% highlight ruby %} +def bar(x=1, **kwargs) + p [x, kwargs] +end + +bar("key" => 42, :sym => 43) + #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] + #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] + +# Use braces to keep the behavior +bar({"key" => 42}, :sym => 43) + #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] +{% endhighlight %} + +Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. + +{% highlight ruby %} +def bar(x=1, sym: nil) + p [x, sym] +end + +bar("key" => 42, :sym => 43) +# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated +# warning: The called method `bar' is defined here +# Ruby 3.0: ArgumentError +{% endhighlight %} + +### 2. Double splat with an empty hash (`**{}`) passes no arguments + +In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. + +{% highlight ruby %} +def foo(*args) + args +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. + +In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. + +{% highlight ruby %} +def foo(x) + x +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: {} + #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated + # warning: The called method `foo' is defined here + #=> Ruby 3.0: ArgumentError: wrong number of arguments +{% endhighlight %} + +### 3. The no-keyword-arguments syntax (`**nil`) is introduced + +You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) + +{% highlight ruby %} +def foo(*args, **nil) +end + +foo(k: 1) + #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) +{% endhighlight %} + +This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: + +{% highlight ruby %} +# If a method accepts rest argument and no `**nil` +def foo(*args) + p args +end + +# Passing keywords are converted to a Hash object (even in Ruby 3.0) +foo(k: 1) #=> [{:k=>1}] + +# If the method is extended to accept a keyword +def foo(*args, mode: false) + p args +end + +# The existing call may break +foo(k: 1) #=> ArgumentError: unknown keyword k +{% endhighlight %} + +## Why we're deprecating the automatic conversion + +The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. + +Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. + +Here is one of the most confusing cases: + +{% highlight ruby %} +def foo(x, **kwargs) + p [x, kwargs] +end + +def bar(x=1, **kwargs) + p [x, kwargs] +end + +foo({}) => [{}, {}] +bar({}) => [1, {}] + +bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +{% endhighlight %} + +In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. + +You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. + +The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo() #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. + +The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. + +## Acknowledgment + +This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. + +## History + +* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. From f93cd654bd38b0e17b278ddd81087a1f1ba65a72 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:47 +0900 Subject: [PATCH 0015/1025] Translate "Separation of positional and keyword arguments in Ruby 3.0" --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 195 +++++++++--------- 1 file changed, 99 insertions(+), 96 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 44cd874cc1..5e80e231d5 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -2,77 +2,81 @@ layout: news_post title: "Separation of positional and keyword arguments in Ruby 3.0" author: "mame" -translator: +translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 -lang: en +lang: ja --- -This article explains the planned incompatibility of keyword arguments in Ruby 3.0 +本記事では、Ruby 3.0で予定されているキーワード引数の非互換性について解説します。 -## tl;dr +## 概要 -In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated`, or * `Passing the keyword argument as the last hash parameter is deprecated`, or * `Splitting the last argument into positional and keyword parameters is deprecated` -In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. +この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 -In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. +Ruby 3では、すべての引数を委譲するメソッドで、位置引数の他に必ずキーワード引数も明示的に委譲しなければなりません。Ruby 2.7以前の委譲の振る舞いを変えたくない場合は、`ruby2_keywords`をお使いください。詳しくは後述の「引数の委譲の扱いについて」をご覧ください。 -## Typical cases +## よくあるケース -Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. +以下はもっともよくあるケースです。Hashではなくキーワードを渡すのにdouble splat演算子(`**`)を使えます。 {% highlight ruby %} -# This method accepts only a keyword argument +# このメソッドはキーワード引数のみを受け取る def foo(k: 1) p k end h = { k: 42 } -# This method call passes a positional Hash argument -# In Ruby 2.7: The Hash is automatically converted to a keyword argument -# In Ruby 3.0: This call raises an ArgumentError +# このメソッド呼び出しは位置引数としてHashを渡している +# Ruby 2.7: このHashは自動でキーワード引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる foo(h) # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call # demo.rb:2: warning: The called method `foo' is defined here # 42 -# If you want to keep the behavior in Ruby 3.0, use double splat +# この振る舞いをRuby 3.0で変えたくない場合はdouble splatを用いる foo(**h) #=> 42 {% endhighlight %} -Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. +別の例: キーワード引数ではなくHashを明示的に渡す場合は中かっこ(`{}`)を使います。 {% highlight ruby %} -# This method accepts one positional argument and a keyword rest argument +# このメソッドは位置引数を1個、残りはキーワード引数を受け取る def bar(h, **kwargs) p h end -# This call passes only a keyword argument and no positional arguments -# In Ruby 2.7: The keyword is converted to a positional Hash argument -# In Ruby 3.0: This call raises an ArgumentError +# この呼び出しではキーワード引数のみが渡され、位置引数は渡されない +# Ruby 2.7: このキーワード引数は自動でHash引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる bar(k: 42) # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated # demo2.rb:2: warning: The called method `bar' is defined here # {:k=>42} -# If you want to keep the behavior in Ruby 3.0, write braces to make it an -# explicit Hash +# この振る舞いをRuby 3.0で変えたくない場合は +# 中かっこで明示的にHashにする bar({ k: 42 }) # => {:k=>42} {% endhighlight %} -## What is deprecated? +## どの動作が非推奨になるか -In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. +Ruby 2では、キーワード引数が末尾のハッシュ位置引数として扱われることがあります。また、末尾のハッシュ引数がキーワード引数として扱われることもあります。 -Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. +この自動変換は場合によっては複雑になりすぎてしまい、本記事末尾で後述するようにトラブルの原因になることがあります。そのため、この自動変換をRuby 2.7で非推奨とし、Ruby 3.0で廃止する予定です。言い換えると、Ruby 3.0のキーワード引数は位置引数と完全に分離されることになります。つまり、キーワード引数を渡したい場合は、常に`foo(k: expr)`または`foo(**expr)`の形にすべきです。(メソッド定義で)キーワード引数を受け取りたい場合は、原則として常に以下のいずれかの形にすべきです。 -Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. +* `def foo(k: default)` +* `def foo(k:)` +* `def foo(**kwargs)` + +なお、キーワード引数を受け取らないメソッドを呼び出すときにキーワード引数を渡した場合の振る舞いは、Ruby 3.0でも変わらない点にご注意ください。たとえば、以下のケースは非推奨にはならず、Ruby 3.0でも引き続き動作します(このキーワード引数は引き続きHash位置引数として扱われます)。 {% highlight ruby %} def foo(kwargs = {}) @@ -82,9 +86,9 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. +変わらない理由は、このスタイルが非常によく用いられていることと、この呼び出し方法では引数の扱いに曖昧な点がないためです。この振る舞いまで禁止してしまうと、得られるメリットが少ないうえに非互換性がさらに増えてしまいます。 -However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: +ただし今後新しいコードを書く場合、このスタイルはおすすめできません(Hashを位置引数として渡す頻度が高く、かつキーワード引数も使う場合を除く)。代わりに、次のようにdouble splat(`**`)をお使いください。 {% highlight ruby %} def foo(**kwargs) @@ -94,21 +98,21 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -## Will my code break on Ruby 2.7? +## Q: 自分のコードはRuby 2.7で動かなくなりますか? -A short answer is "maybe not". +手短かに言うと「壊れない可能性はあります」。 -The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. +Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 -Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. +Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. +非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 -## Handling argument delegation +## 引数の委譲の扱いについて -### Ruby 2.6 or prior +### Ruby 2.6以前の場合 -In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. +Ruby 2では、以下のように1個の`*rest`引数と1個の`&block`引数を受け付けて、この2つの引数を委譲先メソッド(以下の`target`)に渡すことで委譲メソッドを書けます。この振る舞いでは、(1つ以上の)キーワード引数も「位置引数<=>キーワード引数の自動変換」によって暗黙的に扱われます。 {% highlight ruby %} def foo(*args, &block) @@ -116,9 +120,9 @@ def foo(*args, &block) end {% endhighlight %} -### Ruby 3 +### Ruby 3の場合 -You need to explicitly delegate keyword arguments. +以下のようにキーワード引数を明示的に委譲する必要があります。 {% highlight ruby %} def foo(*args, **kwargs, &block) @@ -126,7 +130,7 @@ def foo(*args, **kwargs, &block) end {% endhighlight %} -Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. +別の方法として、Ruby 2.6以前との互換性を考慮する必要がなく、かつ引数を一切改変しないのであれば、以下のようにRuby 2.7で新しく導入される委譲構文(`...`)を利用できます。 {% highlight ruby %} def foo(...) @@ -134,9 +138,9 @@ def foo(...) end {% endhighlight %} -### Ruby 2.7 +### Ruby 2.7の場合 -In short: use `Module#ruby2_keywords` and delegate `*args, &block`. +手短かに言うと、以下のように`Module#ruby2_keywords`を用い、`*args, &block`を委譲します。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -144,13 +148,13 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. +`ruby2_keywords`を指定すると、キーワード引数を末尾のHash引数として受け取れるようになり、他のメソッドを呼び出すときにそれをキーワード引数として渡せます。 -In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. +実際、Ruby 2.7では多くの場面でこの新しい委譲のスタイルを利用できます。ただし1つ既知のエッジケースがあります。次をご覧ください。 -### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 +### Ruby 2.6 / 2.7 / 3で互換性のある委譲スタイル -In short: use `Module#ruby2_keywords` again. +手短かに言うと、ここも「`Module#ruby2_keywords`を使う」となります。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -158,16 +162,16 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) end if RUBY_VERSION < "2.7" {% endhighlight %} ---- +* * * * * -If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: +自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 {% highlight ruby %} def target(*args) @@ -178,35 +182,34 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo({}) #=> Ruby 2.7: [] ({} is dropped) -foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +foo({}) #=> Ruby 2.7: [] ({}を含んでいない) +foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 -As noted in the last line, you can work around this issue by using `**{}`. +上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) -`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 -## Other minor changes +## その他の微細な変更点 -There are three minor changes about keyword arguments in Ruby 2.7. +Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 -### 1. Non-Symbol keys are allowed in keyword arguments +### 1\. キーワード引数で非シンボルキーを利用できるようになった -In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. +Ruby 2.6以前のキーワード引数では、シンボル形式のキーしか利用できませんでした。Ruby 2.7のキーワード引数では、以下のようにシンボル形式でないキーを利用できるようになります。 {% highlight ruby %} def foo(**kwargs) kwargs end foo("key" => 42) - #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments - #=> Ruby 2.7 or later: {"key"=>42} + #=> Ruby 2.6以前: ArgumentError: wrong number of arguments + #=> Ruby 2.7以降: {"key"=>42} {% endhighlight %} -If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. +あるメソッドがオプション引数とキーワード引数を両方とも受け付ける場合、Ruby 2.6では以下のようにシンボル形式のキーと非シンボルキーを両方持つHashオブジェクトが2つに分割されていました。Ruby 2.7では非シンボルキーを利用できるので、どちらも受け取れます。 {% highlight ruby %} def bar(x=1, **kwargs) @@ -217,12 +220,12 @@ bar("key" => 42, :sym => 43) #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] -# Use braces to keep the behavior +# 振る舞いを変えたくない場合は中かっこ{}を使う bar({"key" => 42}, :sym => 43) #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] {% endhighlight %} -Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. +Ruby 2.7では、キーワード引数を明示的に受け付けるがキーワードrest引数(`**kwargs`)を受け取らないメソッドに対して、シンボル形式のキーと非シンボルキーが両方混じったHashやキーワード引数を渡すと、引き続きハッシュを分割して警告を表示します。この振る舞いはRuby 3で廃止されて`ArgumentError`にする予定です。 {% highlight ruby %} def bar(x=1, sym: nil) @@ -230,15 +233,15 @@ def bar(x=1, sym: nil) end bar("key" => 42, :sym => 43) -# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.6と2.7: => [{"key"=>42}, 43] # Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated # warning: The called method `bar' is defined here # Ruby 3.0: ArgumentError {% endhighlight %} -### 2. Double splat with an empty hash (`**{}`) passes no arguments +### 2\. double splatを付けた空ハッシュ(`**{}`)で引数を渡さないようになった -In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. +Ruby 2.6以前は、`**empty_hash`を渡すと位置引数に空のハッシュが渡されました(`[{}]`)。Ruby 2.7以降では引数を渡さなくなります。 {% highlight ruby %} def foo(*args) @@ -247,13 +250,13 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] + #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. +なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -262,51 +265,51 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: {} + #=> Ruby 2.6以前: {} #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated # warning: The called method `foo' is defined here #=> Ruby 3.0: ArgumentError: wrong number of arguments {% endhighlight %} -### 3. The no-keyword-arguments syntax (`**nil`) is introduced +### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 {% highlight ruby %} def foo(*args, **nil) end foo(k: 1) - #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) + #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} -# If a method accepts rest argument and no `**nil` +# メソッドは残りの引数を受け取るが、`**nil`はない状態 def foo(*args) p args end -# Passing keywords are converted to a Hash object (even in Ruby 3.0) +# キーワード引数はHashオブジェクトに変換される(Ruby 3.0でも同じ) foo(k: 1) #=> [{:k=>1}] -# If the method is extended to accept a keyword +# メソッドがキーワード引数を受け取るよう拡張した場合 def foo(*args, mode: false) p args end -# The existing call may break +# 以下の呼び出しが壊れる可能性がある foo(k: 1) #=> ArgumentError: unknown keyword k {% endhighlight %} -## Why we're deprecating the automatic conversion +## 自動変換を非推奨に変える理由 -The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. +当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. +自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 -Here is one of the most confusing cases: +最も混乱を呼ぶケースのひとつを以下に示します。 {% highlight ruby %} def foo(x, **kwargs) @@ -317,17 +320,17 @@ def bar(x=1, **kwargs) p [x, kwargs] end -foo({}) => [{}, {}] -bar({}) => [1, {}] +foo({}) #=> [{}, {}] +bar({}) #=> [1, {}] -bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +bar({}, **{}) #=> 期待は: [{}, {}]だが実際はl: [1, {}] {% endhighlight %} -In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. +Ruby 2の場合、`foo({})`は空のハッシュを通常の引数として1つ渡しますが(`x`に`{}`が代入されるなど)、`bar({})`はキーワード引数を1つ渡します(`kwargs`に`{}`が代入されるなど)。つまり、`any_method({})`は極めてあいまいになります。 -You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. +「`bar({}, **{})`は`x`に明示的に空のハッシュを渡すのでは?」と考える人もいるかもしれませんが、驚いたことに、この期待は裏切られます。Ruby 2.6では`[1, {}]`が出力されるのです。理由は、`**{}`がRuby 2.6のパーサーで無視されるのと、1番目の引数`{}`が自動的にキーワード引数(`**kwargs`)に変換されるためです。この場合`bar({}, {})`という形で呼び出す必要がありますが、これではあまりに見苦しくなります。 -The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. +同じ問題は、残りの引数とキーワード引数を受け取るメソッドにも当てはまります。そのせいで、以下のようなキーワード引数の明示的な委譲は動作しません。 {% highlight ruby %} def target(*args) @@ -338,18 +341,18 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo() #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] +foo() #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 -The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. +自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 -## Acknowledgment +## 謝辞 -This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. +本記事はJeremy EvansとBenoit Dalozeによる丁寧なレビュー(共著と言ってもよいくらいです)をいただきました。 -## History +## 更新履歴 -* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. +* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 From 36c88c2bb991242f7ee04d51666df23d6b2c3d6d Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Thu, 30 Jan 2020 16:49:40 +0900 Subject: [PATCH 0016/1025] Fix untranslated lines --- ...ation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 5e80e231d5..b9aec21a12 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -1,6 +1,6 @@ --- layout: news_post -title: "Separation of positional and keyword arguments in Ruby 3.0" +title: "Ruby 3.0における位置引数とキーワード引数の分離について" author: "mame" translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 @@ -13,8 +13,8 @@ lang: ja Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 -* `Using the last argument as keyword parameters is deprecated`, or -* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Using the last argument as keyword parameters is deprecated` +* `Passing the keyword argument as the last hash parameter is deprecated` * `Splitting the last argument into positional and keyword parameters is deprecated` この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 From 416344e14125e0d3394aa7c45bdc70fc9bb9b734 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 27 Nov 2021 00:48:28 +0900 Subject: [PATCH 0017/1025] Revised the points pointed out in the review. --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index b9aec21a12..38c2aea1c9 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -11,7 +11,9 @@ lang: ja ## 概要 -Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 +この文書では便宜上、必須引数、オプション引数、rest引数、後置引数(つまり、キーワード引数とブロック引数以外の引数)をまとめて「位置引数」と呼びます。 + +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7で警告を表示します。以下のいずれかの警告が表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated` * `Passing the keyword argument as the last hash parameter is deprecated` @@ -100,13 +102,13 @@ foo(k: 1) #=> {:k=>1} ## Q: 自分のコードはRuby 2.7で動かなくなりますか? -手短かに言うと「壊れない可能性はあります」。 +A: たぶん動きます。 -Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 +Ruby 2.7では、原則として、Ruby 3.0で変更される振る舞いについて警告を出すにとどめています。しかし、私たちが軽微とみなした非互換も少しだけ入っています。詳しくは後述の「その他の軽微な変更点」をご覧ください。 -Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 +Ruby 2.7では、警告が表示される点と軽微な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、警告が表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 +非推奨の警告を無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 ## 引数の委譲の扱いについて @@ -162,7 +164,7 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(つまり、**kwargsを受け渡ししないスタイル)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) @@ -186,15 +188,15 @@ foo({}) #=> Ruby 2.7: [] ({}を含んでいない) foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`target`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6がサポート切れになったあとで削除される可能性があります。そのときになったら、キーワード引数を明示的に委譲することをおすすめします(上述のRuby 3向けのコードを参照)。 -## その他の微細な変更点 +## その他の軽微な変更点 -Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 +Ruby 2.7のキーワード引数では、この他に以下の3つの軽微な変更が行われています。 ### 1\. キーワード引数で非シンボルキーを利用できるようになった @@ -256,7 +258,7 @@ foo(**empty_hash) なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡して警告を表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -273,7 +275,7 @@ foo(**empty_hash) ### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、新機能です)。 {% highlight ruby %} def foo(*args, **nil) @@ -283,7 +285,7 @@ foo(k: 1) #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例のrest引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} # メソッドは残りの引数を受け取るが、`**nil`はない状態 @@ -307,7 +309,7 @@ foo(k: 1) #=> ArgumentError: unknown keyword k 当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 +自動変換は、オプション引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 最も混乱を呼ぶケースのひとつを以下に示します。 @@ -345,7 +347,7 @@ foo() #=> Ruby 2.6以前: [{}] #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになり、blockはnilになります。。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 @@ -355,4 +357,4 @@ foo() #=> Ruby 2.6以前: [{}] ## 更新履歴 -* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 +* 更新 2019-12-25: 2.7.0-rc2で警告メッセージが若干変更され、警告抑制APIが追加された。 From 177e9c20ebd9f893fc9c1350840a507230d5d102 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 29 Nov 2021 09:43:56 +0900 Subject: [PATCH 0018/1025] Markup --- ...eparation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 38c2aea1c9..7b981ae761 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -347,7 +347,7 @@ foo() #=> Ruby 2.6以前: [{}] #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになり、blockはnilになります。。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになり、`block`は`nil`になります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 From 2ddada69b79bbcce70fbf3e8888b7fe805dbf27a Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:17 +0900 Subject: [PATCH 0019/1025] Add en doc --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md new file mode 100644 index 0000000000..44cd874cc1 --- /dev/null +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -0,0 +1,355 @@ +--- +layout: news_post +title: "Separation of positional and keyword arguments in Ruby 3.0" +author: "mame" +translator: +date: 2019-12-12 12:00:00 +0000 +lang: en +--- + +This article explains the planned incompatibility of keyword arguments in Ruby 3.0 + +## tl;dr + +In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: + +* `Using the last argument as keyword parameters is deprecated`, or +* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Splitting the last argument into positional and keyword parameters is deprecated` + +In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. + +In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. + +## Typical cases + +Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. + +{% highlight ruby %} +# This method accepts only a keyword argument +def foo(k: 1) + p k +end + +h = { k: 42 } + +# This method call passes a positional Hash argument +# In Ruby 2.7: The Hash is automatically converted to a keyword argument +# In Ruby 3.0: This call raises an ArgumentError +foo(h) + # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call + # demo.rb:2: warning: The called method `foo' is defined here + # 42 + +# If you want to keep the behavior in Ruby 3.0, use double splat +foo(**h) #=> 42 +{% endhighlight %} + +Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. + +{% highlight ruby %} +# This method accepts one positional argument and a keyword rest argument +def bar(h, **kwargs) + p h +end + +# This call passes only a keyword argument and no positional arguments +# In Ruby 2.7: The keyword is converted to a positional Hash argument +# In Ruby 3.0: This call raises an ArgumentError +bar(k: 42) + # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated + # demo2.rb:2: warning: The called method `bar' is defined here + # {:k=>42} + +# If you want to keep the behavior in Ruby 3.0, write braces to make it an +# explicit Hash +bar({ k: 42 }) # => {:k=>42} +{% endhighlight %} + +## What is deprecated? + +In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. + +Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. + +Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. + +{% highlight ruby %} +def foo(kwargs = {}) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. + +However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end + +foo(k: 1) #=> {:k=>1} +{% endhighlight %} + +## Will my code break on Ruby 2.7? + +A short answer is "maybe not". + +The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. + +Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. + +If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. + +## Handling argument delegation + +### Ruby 2.6 or prior + +In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. + +{% highlight ruby %} +def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +### Ruby 3 + +You need to explicitly delegate keyword arguments. + +{% highlight ruby %} +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end +{% endhighlight %} + +Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. + +{% highlight ruby %} +def foo(...) + target(...) +end +{% endhighlight %} + +### Ruby 2.7 + +In short: use `Module#ruby2_keywords` and delegate `*args, &block`. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. + +In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. + +### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 + +In short: use `Module#ruby2_keywords` again. + +{% highlight ruby %} +ruby2_keywords def foo(*args, &block) + target(*args, &block) +end +{% endhighlight %} + +Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: + +{% highlight ruby %} +def ruby2_keywords(*) +end if RUBY_VERSION < "2.7" +{% endhighlight %} + +--- + +If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo({}) #=> Ruby 2.7: [] ({} is dropped) +foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +{% endhighlight %} + +An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. + +As noted in the last line, you can work around this issue by using `**{}`. + +If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) +`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). + +## Other minor changes + +There are three minor changes about keyword arguments in Ruby 2.7. + +### 1. Non-Symbol keys are allowed in keyword arguments + +In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. + +{% highlight ruby %} +def foo(**kwargs) + kwargs +end +foo("key" => 42) + #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments + #=> Ruby 2.7 or later: {"key"=>42} +{% endhighlight %} + +If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. + +{% highlight ruby %} +def bar(x=1, **kwargs) + p [x, kwargs] +end + +bar("key" => 42, :sym => 43) + #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] + #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] + +# Use braces to keep the behavior +bar({"key" => 42}, :sym => 43) + #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] +{% endhighlight %} + +Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. + +{% highlight ruby %} +def bar(x=1, sym: nil) + p [x, sym] +end + +bar("key" => 42, :sym => 43) +# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated +# warning: The called method `bar' is defined here +# Ruby 3.0: ArgumentError +{% endhighlight %} + +### 2. Double splat with an empty hash (`**{}`) passes no arguments + +In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. + +{% highlight ruby %} +def foo(*args) + args +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. + +In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. + +{% highlight ruby %} +def foo(x) + x +end + +empty_hash = {} +foo(**empty_hash) + #=> Ruby 2.6 or before: {} + #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated + # warning: The called method `foo' is defined here + #=> Ruby 3.0: ArgumentError: wrong number of arguments +{% endhighlight %} + +### 3. The no-keyword-arguments syntax (`**nil`) is introduced + +You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) + +{% highlight ruby %} +def foo(*args, **nil) +end + +foo(k: 1) + #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) +{% endhighlight %} + +This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: + +{% highlight ruby %} +# If a method accepts rest argument and no `**nil` +def foo(*args) + p args +end + +# Passing keywords are converted to a Hash object (even in Ruby 3.0) +foo(k: 1) #=> [{:k=>1}] + +# If the method is extended to accept a keyword +def foo(*args, mode: false) + p args +end + +# The existing call may break +foo(k: 1) #=> ArgumentError: unknown keyword k +{% endhighlight %} + +## Why we're deprecating the automatic conversion + +The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. + +Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. + +Here is one of the most confusing cases: + +{% highlight ruby %} +def foo(x, **kwargs) + p [x, kwargs] +end + +def bar(x=1, **kwargs) + p [x, kwargs] +end + +foo({}) => [{}, {}] +bar({}) => [1, {}] + +bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +{% endhighlight %} + +In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. + +You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. + +The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. + +{% highlight ruby %} +def target(*args) + p args +end + +def foo(*args, **kwargs, &block) + target(*args, **kwargs, &block) +end + +foo() #=> Ruby 2.6 or before: [{}] + #=> Ruby 2.7 or later: [] +{% endhighlight %} + +`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. + +The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. + +## Acknowledgment + +This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. + +## History + +* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. From b98d7083356c9cf8ecab750872108243561e38cb Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:47 +0900 Subject: [PATCH 0020/1025] Translate "Separation of positional and keyword arguments in Ruby 3.0" --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 195 +++++++++--------- 1 file changed, 99 insertions(+), 96 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 44cd874cc1..5e80e231d5 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -2,77 +2,81 @@ layout: news_post title: "Separation of positional and keyword arguments in Ruby 3.0" author: "mame" -translator: +translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 -lang: en +lang: ja --- -This article explains the planned incompatibility of keyword arguments in Ruby 3.0 +本記事では、Ruby 3.0で予定されているキーワード引数の非互換性について解説します。 -## tl;dr +## 概要 -In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code: +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated`, or * `Passing the keyword argument as the last hash parameter is deprecated`, or * `Splitting the last argument into positional and keyword parameters is deprecated` -In most cases, you can avoid the incompatibility by adding the _double splat_ operator. It explicitly specifies passing keyword arguments instead of a `Hash` object. Likewise, you may add braces `{}` to explicitly pass a `Hash` object, instead of keyword arguments. Read the section "Typical cases" below for more details. +この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 -In Ruby 3, a method delegating all arguments must explicitly delegate keyword arguments in addition to positional arguments. If you want to keep the delegation behavior found in Ruby 2.7 and earlier, use `ruby2_keywords`. See the "Handling argument delegation" section below for more details. +Ruby 3では、すべての引数を委譲するメソッドで、位置引数の他に必ずキーワード引数も明示的に委譲しなければなりません。Ruby 2.7以前の委譲の振る舞いを変えたくない場合は、`ruby2_keywords`をお使いください。詳しくは後述の「引数の委譲の扱いについて」をご覧ください。 -## Typical cases +## よくあるケース -Here is the most typical case. You can use double splat operator (`**`) to pass keywords instead of a Hash. +以下はもっともよくあるケースです。Hashではなくキーワードを渡すのにdouble splat演算子(`**`)を使えます。 {% highlight ruby %} -# This method accepts only a keyword argument +# このメソッドはキーワード引数のみを受け取る def foo(k: 1) p k end h = { k: 42 } -# This method call passes a positional Hash argument -# In Ruby 2.7: The Hash is automatically converted to a keyword argument -# In Ruby 3.0: This call raises an ArgumentError +# このメソッド呼び出しは位置引数としてHashを渡している +# Ruby 2.7: このHashは自動でキーワード引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる foo(h) # => demo.rb:11: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call # demo.rb:2: warning: The called method `foo' is defined here # 42 -# If you want to keep the behavior in Ruby 3.0, use double splat +# この振る舞いをRuby 3.0で変えたくない場合はdouble splatを用いる foo(**h) #=> 42 {% endhighlight %} -Here is another case. You can use braces (`{}`) to pass a Hash instead of keywords explicitly. +別の例: キーワード引数ではなくHashを明示的に渡す場合は中かっこ(`{}`)を使います。 {% highlight ruby %} -# This method accepts one positional argument and a keyword rest argument +# このメソッドは位置引数を1個、残りはキーワード引数を受け取る def bar(h, **kwargs) p h end -# This call passes only a keyword argument and no positional arguments -# In Ruby 2.7: The keyword is converted to a positional Hash argument -# In Ruby 3.0: This call raises an ArgumentError +# この呼び出しではキーワード引数のみが渡され、位置引数は渡されない +# Ruby 2.7: このキーワード引数は自動でHash引数に変換される +# Ruby 3.0: この呼び出しはArgumentErrorになる bar(k: 42) # => demo2.rb:9: warning: Passing the keyword argument as the last hash parameter is deprecated # demo2.rb:2: warning: The called method `bar' is defined here # {:k=>42} -# If you want to keep the behavior in Ruby 3.0, write braces to make it an -# explicit Hash +# この振る舞いをRuby 3.0で変えたくない場合は +# 中かっこで明示的にHashにする bar({ k: 42 }) # => {:k=>42} {% endhighlight %} -## What is deprecated? +## どの動作が非推奨になるか -In Ruby 2, keyword arguments can be treated as the last positional Hash argument and a last positional Hash argument can be treated as keyword arguments. +Ruby 2では、キーワード引数が末尾のハッシュ位置引数として扱われることがあります。また、末尾のハッシュ引数がキーワード引数として扱われることもあります。 -Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it's now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use `foo(k: expr)` or `foo(**expr)`. If you want to accept keyword arguments, in principle you should always use `def foo(k: default)` or `def foo(k:)` or `def foo(**kwargs)`. +この自動変換は場合によっては複雑になりすぎてしまい、本記事末尾で後述するようにトラブルの原因になることがあります。そのため、この自動変換をRuby 2.7で非推奨とし、Ruby 3.0で廃止する予定です。言い換えると、Ruby 3.0のキーワード引数は位置引数と完全に分離されることになります。つまり、キーワード引数を渡したい場合は、常に`foo(k: expr)`または`foo(**expr)`の形にすべきです。(メソッド定義で)キーワード引数を受け取りたい場合は、原則として常に以下のいずれかの形にすべきです。 -Note that Ruby 3.0 doesn't behave differently when calling a method which doesn't accept keyword arguments with keyword arguments. For instance, the following case is not going to be deprecated and will keep working in Ruby 3.0. The keyword arguments are still treated as a positional Hash argument. +* `def foo(k: default)` +* `def foo(k:)` +* `def foo(**kwargs)` + +なお、キーワード引数を受け取らないメソッドを呼び出すときにキーワード引数を渡した場合の振る舞いは、Ruby 3.0でも変わらない点にご注意ください。たとえば、以下のケースは非推奨にはならず、Ruby 3.0でも引き続き動作します(このキーワード引数は引き続きHash位置引数として扱われます)。 {% highlight ruby %} def foo(kwargs = {}) @@ -82,9 +86,9 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -This is because this style is used very frequently, and there is no ambiguity in how the argument should be treated. Prohibiting this conversion would result in additional incompatibility for little benefit. +変わらない理由は、このスタイルが非常によく用いられていることと、この呼び出し方法では引数の扱いに曖昧な点がないためです。この振る舞いまで禁止してしまうと、得られるメリットが少ないうえに非互換性がさらに増えてしまいます。 -However, this style is not recommended in new code, unless you are often passing a Hash as a positional argument, and are also using keyword arguments. Otherwise, use double splat: +ただし今後新しいコードを書く場合、このスタイルはおすすめできません(Hashを位置引数として渡す頻度が高く、かつキーワード引数も使う場合を除く)。代わりに、次のようにdouble splat(`**`)をお使いください。 {% highlight ruby %} def foo(**kwargs) @@ -94,21 +98,21 @@ end foo(k: 1) #=> {:k=>1} {% endhighlight %} -## Will my code break on Ruby 2.7? +## Q: 自分のコードはRuby 2.7で動かなくなりますか? -A short answer is "maybe not". +手短かに言うと「壊れない可能性はあります」。 -The changes in Ruby 2.7 are designed as a migration path towards 3.0. While in principle, Ruby 2.7 only warns against behaviors that will change in Ruby 3, it includes some incompatible changes we consider to be minor. See the "Other minor changes" section for details. +Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 -Except for the warnings and minor changes, Ruby 2.7 attempts to keep the compatibility with Ruby 2.6. So, your code will probably work on Ruby 2.7, though it may emit warnings. And by running it on Ruby 2.7, you can check if your code is ready for Ruby 3.0. +Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -If you want to disable the deprecation warnings, please use a command-line argument `-W:no-deprecated` or add `Warning[:deprecated] = false` to your code. +非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 -## Handling argument delegation +## 引数の委譲の扱いについて -### Ruby 2.6 or prior +### Ruby 2.6以前の場合 -In Ruby 2, you can write a delegation method by accepting a `*rest` argument and a `&block` argument, and passing the two to the target method. In this behavior, the keyword arguments are also implicitly handled by the automatic conversion between positional and keyword arguments. +Ruby 2では、以下のように1個の`*rest`引数と1個の`&block`引数を受け付けて、この2つの引数を委譲先メソッド(以下の`target`)に渡すことで委譲メソッドを書けます。この振る舞いでは、(1つ以上の)キーワード引数も「位置引数<=>キーワード引数の自動変換」によって暗黙的に扱われます。 {% highlight ruby %} def foo(*args, &block) @@ -116,9 +120,9 @@ def foo(*args, &block) end {% endhighlight %} -### Ruby 3 +### Ruby 3の場合 -You need to explicitly delegate keyword arguments. +以下のようにキーワード引数を明示的に委譲する必要があります。 {% highlight ruby %} def foo(*args, **kwargs, &block) @@ -126,7 +130,7 @@ def foo(*args, **kwargs, &block) end {% endhighlight %} -Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don't alter any arguments, you can use the new delegation syntax (`...`) that is introduced in Ruby 2.7. +別の方法として、Ruby 2.6以前との互換性を考慮する必要がなく、かつ引数を一切改変しないのであれば、以下のようにRuby 2.7で新しく導入される委譲構文(`...`)を利用できます。 {% highlight ruby %} def foo(...) @@ -134,9 +138,9 @@ def foo(...) end {% endhighlight %} -### Ruby 2.7 +### Ruby 2.7の場合 -In short: use `Module#ruby2_keywords` and delegate `*args, &block`. +手短かに言うと、以下のように`Module#ruby2_keywords`を用い、`*args, &block`を委譲します。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -144,13 +148,13 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -`ruby2_keywords` accepts keyword arguments as the last Hash argument, and passes it as keyword arguments when calling the other method. +`ruby2_keywords`を指定すると、キーワード引数を末尾のHash引数として受け取れるようになり、他のメソッドを呼び出すときにそれをキーワード引数として渡せます。 -In fact, Ruby 2.7 allows the new style of delegation in many cases. However, there is a known corner case. See the next section. +実際、Ruby 2.7では多くの場面でこの新しい委譲のスタイルを利用できます。ただし1つ既知のエッジケースがあります。次をご覧ください。 -### A compatible delegation that works on Ruby 2.6, 2.7 and Ruby 3 +### Ruby 2.6 / 2.7 / 3で互換性のある委譲スタイル -In short: use `Module#ruby2_keywords` again. +手短かに言うと、ここも「`Module#ruby2_keywords`を使う」となります。 {% highlight ruby %} ruby2_keywords def foo(*args, &block) @@ -158,16 +162,16 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -Unfortunately, we need to use the old-style delegation (i.e., no `**kwargs`) because Ruby 2.6 or prior does not handle the new delegation style correctly. This is one of the reasons of the keyword argument separation; the details are described in the final section. And `ruby2_keywords` allows you to run the old style even in Ruby 2.7 and 3.0. As there is no `ruby2_keywords` defined in 2.6 or prior, please use the [ruby2_keywords gem](https://rubygems.org/gems/ruby2_keywords) or define it yourself: +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) end if RUBY_VERSION < "2.7" {% endhighlight %} ---- +* * * * * -If your code doesn't have to run on Ruby 2.6 or older, you may try the new style in Ruby 2.7. In almost all cases, it works. Note that, however, there are unfortunate corner cases as follows: +自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 {% highlight ruby %} def target(*args) @@ -178,35 +182,34 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo({}) #=> Ruby 2.7: [] ({} is dropped) -foo({}, **{}) #=> Ruby 2.7: [{}] (You can pass {} by explicitly passing "no" keywords) +foo({}) #=> Ruby 2.7: [] ({}を含んでいない) +foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -An empty Hash argument is automatically converted and absorbed into `**kwargs`, and the delegation call removes the empty keyword hash, so no argument is passed to `target`. As far as we know, this is the only corner case. +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 -As noted in the last line, you can work around this issue by using `**{}`. +上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -If you really worry about the portability, use `ruby2_keywords`. (Acknowledge that Ruby 2.6 or before themselves have tons of corner cases in keyword arguments. :-) -`ruby2_keywords` might be removed in the future after Ruby 2.6 reaches end-of-life. At that point, we recommend to explicitly delegate keyword arguments (see Ruby 3 code above). +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 -## Other minor changes +## その他の微細な変更点 -There are three minor changes about keyword arguments in Ruby 2.7. +Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 -### 1. Non-Symbol keys are allowed in keyword arguments +### 1\. キーワード引数で非シンボルキーを利用できるようになった -In Ruby 2.6 or before, only Symbol keys were allowed in keyword arguments. In Ruby 2.7, keyword arguments can use non-Symbol keys. +Ruby 2.6以前のキーワード引数では、シンボル形式のキーしか利用できませんでした。Ruby 2.7のキーワード引数では、以下のようにシンボル形式でないキーを利用できるようになります。 {% highlight ruby %} def foo(**kwargs) kwargs end foo("key" => 42) - #=> Ruby 2.6 or before: ArgumentError: wrong number of arguments - #=> Ruby 2.7 or later: {"key"=>42} + #=> Ruby 2.6以前: ArgumentError: wrong number of arguments + #=> Ruby 2.7以降: {"key"=>42} {% endhighlight %} -If a method accepts both optional and keyword arguments, the Hash object that has both Symbol keys and non-Symbol keys was split in two in Ruby 2.6. In Ruby 2.7, both are accepted as keywords because non-Symbol keys are allowed. +あるメソッドがオプション引数とキーワード引数を両方とも受け付ける場合、Ruby 2.6では以下のようにシンボル形式のキーと非シンボルキーを両方持つHashオブジェクトが2つに分割されていました。Ruby 2.7では非シンボルキーを利用できるので、どちらも受け取れます。 {% highlight ruby %} def bar(x=1, **kwargs) @@ -217,12 +220,12 @@ bar("key" => 42, :sym => 43) #=> Ruby 2.6: [{"key"=>42}, {:sym=>43}] #=> Ruby 2.7: [1, {"key"=>42, :sym=>43}] -# Use braces to keep the behavior +# 振る舞いを変えたくない場合は中かっこ{}を使う bar({"key" => 42}, :sym => 43) #=> Ruby 2.6 and 2.7: [{"key"=>42}, {:sym=>43}] {% endhighlight %} -Ruby 2.7 still splits hashes with a warning if passing a Hash or keyword arguments with both Symbol and non-Symbol keys to a method that accepts explicit keywords but no keyword rest argument (`**kwargs`). This behavior will be removed in Ruby 3, and an `ArgumentError` will be raised. +Ruby 2.7では、キーワード引数を明示的に受け付けるがキーワードrest引数(`**kwargs`)を受け取らないメソッドに対して、シンボル形式のキーと非シンボルキーが両方混じったHashやキーワード引数を渡すと、引き続きハッシュを分割して警告を表示します。この振る舞いはRuby 3で廃止されて`ArgumentError`にする予定です。 {% highlight ruby %} def bar(x=1, sym: nil) @@ -230,15 +233,15 @@ def bar(x=1, sym: nil) end bar("key" => 42, :sym => 43) -# Ruby 2.6 and 2.7: => [{"key"=>42}, 43] +# Ruby 2.6と2.7: => [{"key"=>42}, 43] # Ruby 2.7: warning: Splitting the last argument into positional and keyword parameters is deprecated # warning: The called method `bar' is defined here # Ruby 3.0: ArgumentError {% endhighlight %} -### 2. Double splat with an empty hash (`**{}`) passes no arguments +### 2\. double splatを付けた空ハッシュ(`**{}`)で引数を渡さないようになった -In Ruby 2.6 or before, passing `**empty_hash` passes an empty Hash as a positional argument. In Ruby 2.7 or later, it passes no arguments. +Ruby 2.6以前は、`**empty_hash`を渡すと位置引数に空のハッシュが渡されました(`[{}]`)。Ruby 2.7以降では引数を渡さなくなります。 {% highlight ruby %} def foo(*args) @@ -247,13 +250,13 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] + #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -Note that `foo(**{})` passes nothing in both Ruby 2.6 and 2.7. In Ruby 2.6 and before, `**{}` is removed by the parser, and in Ruby 2.7 and above, it is treated the same as `**empty_hash`, allowing for an easy way to pass no keyword arguments to a method. +なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -In Ruby 2.7, when calling a method with an insufficient number of required positional arguments, `foo(**empty_hash)` passes an empty hash with a warning emitted, for compatibility with Ruby 2.6. This behavior will be removed in 3.0. +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -262,51 +265,51 @@ end empty_hash = {} foo(**empty_hash) - #=> Ruby 2.6 or before: {} + #=> Ruby 2.6以前: {} #=> Ruby 2.7: warning: Passing the keyword argument as the last hash parameter is deprecated # warning: The called method `foo' is defined here #=> Ruby 3.0: ArgumentError: wrong number of arguments {% endhighlight %} -### 3. The no-keyword-arguments syntax (`**nil`) is introduced +### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -You can use `**nil` in a method definition to explicitly mark the method accepts no keyword arguments. Calling such methods with keyword arguments will result in an `ArgumentError`. (This is actually a new feature, not an incompatibility) +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 {% highlight ruby %} def foo(*args, **nil) end foo(k: 1) - #=> Ruby 2.7 or later: no keywords accepted (ArgumentError) + #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -This is useful to make it explicit that the method does not accept keyword arguments. Otherwise, the keywords are absorbed in the rest argument in the above example. If you extend a method to accept keyword arguments, the method may have incompatibility as follows: +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} -# If a method accepts rest argument and no `**nil` +# メソッドは残りの引数を受け取るが、`**nil`はない状態 def foo(*args) p args end -# Passing keywords are converted to a Hash object (even in Ruby 3.0) +# キーワード引数はHashオブジェクトに変換される(Ruby 3.0でも同じ) foo(k: 1) #=> [{:k=>1}] -# If the method is extended to accept a keyword +# メソッドがキーワード引数を受け取るよう拡張した場合 def foo(*args, mode: false) p args end -# The existing call may break +# 以下の呼び出しが壊れる可能性がある foo(k: 1) #=> ArgumentError: unknown keyword k {% endhighlight %} -## Why we're deprecating the automatic conversion +## 自動変換を非推奨に変える理由 -The automatic conversion initially appeared to be a good idea, and worked well in many cases. However, it had too many corner cases, and we have received many bug reports about the behavior. +当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -Automatic conversion does not work well when a method accepts optional positional arguments and keyword arguments. Some people expect the last Hash object to be treated as a positional argument, and others expect it to be converted to keyword arguments. +自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 -Here is one of the most confusing cases: +最も混乱を呼ぶケースのひとつを以下に示します。 {% highlight ruby %} def foo(x, **kwargs) @@ -317,17 +320,17 @@ def bar(x=1, **kwargs) p [x, kwargs] end -foo({}) => [{}, {}] -bar({}) => [1, {}] +foo({}) #=> [{}, {}] +bar({}) #=> [1, {}] -bar({}, **{}) => expected: [{}, {}], actual: [1, {}] +bar({}, **{}) #=> 期待は: [{}, {}]だが実際はl: [1, {}] {% endhighlight %} -In Ruby 2, `foo({})` passes an empty hash as a normal argument (i.e., `{}` is assigned to `x`), while `bar({})` passes a keyword argument (i.e, `{}` is assigned to `kwargs`). So `any_method({})` is very ambiguous. +Ruby 2の場合、`foo({})`は空のハッシュを通常の引数として1つ渡しますが(`x`に`{}`が代入されるなど)、`bar({})`はキーワード引数を1つ渡します(`kwargs`に`{}`が代入されるなど)。つまり、`any_method({})`は極めてあいまいになります。 -You may think of `bar({}, **{})` to pass the empty hash to `x` explicitly. Surprisingly, it does not work as you expected; it still prints `[1, {}]` in Ruby 2.6. This is because `**{}` is ignored by the parser in Ruby 2.6, and the first argument `{}` is automatically converted to keywords (`**kwargs`). In this case, you need to call `bar({}, {})`, which is very weird. +「`bar({}, **{})`は`x`に明示的に空のハッシュを渡すのでは?」と考える人もいるかもしれませんが、驚いたことに、この期待は裏切られます。Ruby 2.6では`[1, {}]`が出力されるのです。理由は、`**{}`がRuby 2.6のパーサーで無視されるのと、1番目の引数`{}`が自動的にキーワード引数(`**kwargs`)に変換されるためです。この場合`bar({}, {})`という形で呼び出す必要がありますが、これではあまりに見苦しくなります。 -The same issues also apply to methods that accept rest and keyword arguments. This makes explicit delegation of keyword arguments not work. +同じ問題は、残りの引数とキーワード引数を受け取るメソッドにも当てはまります。そのせいで、以下のようなキーワード引数の明示的な委譲は動作しません。 {% highlight ruby %} def target(*args) @@ -338,18 +341,18 @@ def foo(*args, **kwargs, &block) target(*args, **kwargs, &block) end -foo() #=> Ruby 2.6 or before: [{}] - #=> Ruby 2.7 or later: [] +foo() #=> Ruby 2.6以前: [{}] + #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()` passes no arguments, but `target` receives an empty hash argument in Ruby 2.6. This is because the method `foo` delegates keywords (`**kwargs`) explicitly. When `foo()` is called, `args` is an empty Array, `kwargs` is an empty Hash, and `block` is `nil`. And then `target(*args, **kwargs, &block)` passes an empty Hash as an argument because `**kwargs` is automatically converted to a positional Hash argument. +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 -The automatic conversion not only confuses people but also makes the method less extensible. See [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183) for more details about the reasons for the change in behavior, and why certain implementation choices were made. +自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 -## Acknowledgment +## 謝辞 -This article was kindly reviewed (or even co-authored) by Jeremy Evans and Benoit Daloze. +本記事はJeremy EvansとBenoit Dalozeによる丁寧なレビュー(共著と言ってもよいくらいです)をいただきました。 -## History +## 更新履歴 -* Updated 2019-12-25: In 2.7.0-rc2, the warning message was slightly changed, and an API to suppress the warnings was added. +* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 From c82970710444b36e5baf1f6315b388d809062b1a Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Thu, 30 Jan 2020 16:49:40 +0900 Subject: [PATCH 0021/1025] Fix untranslated lines --- ...ation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 5e80e231d5..b9aec21a12 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -1,6 +1,6 @@ --- layout: news_post -title: "Separation of positional and keyword arguments in Ruby 3.0" +title: "Ruby 3.0における位置引数とキーワード引数の分離について" author: "mame" translator: "hachi8833" date: 2019-12-12 12:00:00 +0000 @@ -13,8 +13,8 @@ lang: ja Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 -* `Using the last argument as keyword parameters is deprecated`, or -* `Passing the keyword argument as the last hash parameter is deprecated`, or +* `Using the last argument as keyword parameters is deprecated` +* `Passing the keyword argument as the last hash parameter is deprecated` * `Splitting the last argument into positional and keyword parameters is deprecated` この非互換性は、double splat演算子(`**`)を追加することでほぼ回避できます。これにより、`Hash`オブジェクトではなくキーワード引数を渡すことが明示的に指定されます。同様に、キーワード引数ではなく`Hash`オブジェクトを明示的に渡したい場合は中かっこ(`{}`)を追加できます。詳しくは後述の「典型的なケース」をご覧ください。 From db32bd844eff125ad3ddd8e47a6ee8285f3c57b1 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 27 Nov 2021 00:48:28 +0900 Subject: [PATCH 0022/1025] Revised the points pointed out in the review. --- ...ional-and-keyword-arguments-in-ruby-3-0.md | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index b9aec21a12..38c2aea1c9 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -11,7 +11,9 @@ lang: ja ## 概要 -Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 +この文書では便宜上、必須引数、オプション引数、rest引数、後置引数(つまり、キーワード引数とブロック引数以外の引数)をまとめて「位置引数」と呼びます。 + +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7で警告を表示します。以下のいずれかの警告が表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated` * `Passing the keyword argument as the last hash parameter is deprecated` @@ -100,13 +102,13 @@ foo(k: 1) #=> {:k=>1} ## Q: 自分のコードはRuby 2.7で動かなくなりますか? -手短かに言うと「壊れない可能性はあります」。 +A: たぶん動きます。 -Ruby 2.7におけるこの変更は、3.0への移行パスとして設計されています。あくまで原則としてですが、Ruby 2.7ではRuby 3.0で変更される振る舞いについてwarningを出すにとどめており、warningの中には私たちが微細とみなしている変更点も若干含まれます。詳しくは後述の「その他の微細な変更点」をご覧ください。 +Ruby 2.7では、原則として、Ruby 3.0で変更される振る舞いについて警告を出すにとどめています。しかし、私たちが軽微とみなした非互換も少しだけ入っています。詳しくは後述の「その他の軽微な変更点」をご覧ください。 -Ruby 2.7では、warningが表示される点と微細な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、warningが表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 +Ruby 2.7では、警告が表示される点と軽微な変更点以外を除いてRuby 2.6との互換性を保とうとしています。つまり、あなたのコードはRuby 2.7でもおそらく動作しますが、警告が表示される可能性はあります。あなたのコードをRuby 2.7で実行すれば、Ruby 3.0の準備ができているかどうかをチェックできます。 -非推奨のwarningを無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 +非推奨の警告を無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 ## 引数の委譲の扱いについて @@ -162,7 +164,7 @@ ruby2_keywords def foo(*args, &block) end {% endhighlight %} -残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(`**kwargs`を使わないなど)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 +残念ながら、Ruby 2.6以前では新しい委譲スタイルを正しく扱えないため、旧来の委譲スタイル(つまり、**kwargsを受け渡ししないスタイル)を使う必要があります。これは、キーワード引数を分離した理由のひとつでもあります(詳しくは本記事末尾をご覧ください)。`ruby2_keywords`を用いれば、Ruby 2.7や3.0でも旧来の委譲スタイルを引き続き利用できます。2.6以前のRubyでは`ruby2_keywords`が定義されていないので、[ruby2_keywords](https://rubygems.org/gems/ruby2_keywords) gemを使うか、以下を手動で定義します。 {% highlight ruby %} def ruby2_keywords(*) @@ -186,15 +188,15 @@ foo({}) #=> Ruby 2.7: [] ({}を含んでいない) foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「ない」ことを明示できる) {% endhighlight %} -上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`targe`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 +上のコードでは、空のHash引数が自動的に変換されて`**kwargs`に吸い込まれ、この空のキーワードハッシュは委譲の呼び出しで削除されます。このため、`target`には引数がまったく渡されなくなります。私たちが把握している範囲では、これが唯一のエッジケースです。 上のコードの最下部に書いたように、`**{}`を渡すことでこの問題を回避できます。 -移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6が役目を終えたときに削除される可能性があります。現時点で私たちがおすすめできるのは、キーワード引数を明示的に委譲することです(上述のRuby 3向けのコードを参照)。 +移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6がサポート切れになったあとで削除される可能性があります。そのときになったら、キーワード引数を明示的に委譲することをおすすめします(上述のRuby 3向けのコードを参照)。 -## その他の微細な変更点 +## その他の軽微な変更点 -Ruby 2.7のキーワード引数では、この他に以下の3つのマイナーチェンジが行われています。 +Ruby 2.7のキーワード引数では、この他に以下の3つの軽微な変更が行われています。 ### 1\. キーワード引数で非シンボルキーを利用できるようになった @@ -256,7 +258,7 @@ foo(**empty_hash) なお、`foo(**{})`はRuby 2.6以前とRuby 2.7のどちらの場合も引数を渡さず、`**{}`がパーサーによって削除される点にご注意ください。また、Ruby 2.7以降ではどちらも`**empty_hash`として同じに扱われるので、メソッドにキーワード引数を渡さないようにする指定が楽に行なえます。 -Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡してwarningを表示します。この振る舞いはRuby 3.0で廃止されます。 +Ruby 2.7では、あるメソッド呼び出しで必須とされる位置引数の個数が不足している場合、Ruby 2.6との互換性を保つために`foo(**empty_hash)`は空のハッシュを渡して警告を表示します。この振る舞いはRuby 3.0で廃止されます。 {% highlight ruby %} def foo(x) @@ -273,7 +275,7 @@ foo(**empty_hash) ### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される -メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、事実上新機能です)。 +メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、新機能です)。 {% highlight ruby %} def foo(*args, **nil) @@ -283,7 +285,7 @@ foo(k: 1) #=> Ruby 2.7以降: no keywords accepted (ArgumentError) {% endhighlight %} -この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例の他の引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 +この新構文は、メソッドがキーワード引数を受け取らないことを明示的に指定するのに有用です。これを使わない場合、キーワード引数は上述の例のrest引数に吸い込まれます。メソッドを拡張してキーワード引数を受け取るようにする場合、以下のような非互換性が発生する可能性があります。 {% highlight ruby %} # メソッドは残りの引数を受け取るが、`**nil`はない状態 @@ -307,7 +309,7 @@ foo(k: 1) #=> ArgumentError: unknown keyword k 当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 -自動変換は、オプションの位置引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 +自動変換は、オプション引数とキーワード引数をどちらも受け取るメソッドではうまく動きません。末尾のHashオブジェクトを位置引数として扱うことを期待する人々もいれば、末尾のHashオブジェクトをキーワード引数として扱うことを期待する人々もいました。 最も混乱を呼ぶケースのひとつを以下に示します。 @@ -345,7 +347,7 @@ foo() #=> Ruby 2.6以前: [{}] #=> Ruby 2.7以降: [] {% endhighlight %} -`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになります。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 +`foo()`には引数がありませんが、Ruby 2.6では空のハッシュ引数が`target`に渡されます。理由は、メソッド`foo`が明示的にキーワード(`**kwargs`)を委譲しているためです。`foo()`が呼び出されると、`args`は空のArrayになり、`kwargs`は空のHashになり、blockはnilになります。。そして`target(*args, **kwargs, &block)`は空のHashを引数として1つ渡します。理由は、`**kwargs`が自動的にHash位置引数に変換されるためです。 自動変換は開発者を混乱させるのみならず、メソッドの拡張性も弱めてしまいます。振る舞いが変更された理由や、特定の実装が選択された理由について詳しくは[Feature #14183](https://bugs.ruby-lang.org/issues/14183)をご覧ください。 @@ -355,4 +357,4 @@ foo() #=> Ruby 2.6以前: [{}] ## 更新履歴 -* 更新 2019-12-25: 2.7.0-rc2でwarningメッセージが若干変更され、warning抑制APIが追加された。 +* 更新 2019-12-25: 2.7.0-rc2で警告メッセージが若干変更され、警告抑制APIが追加された。 From a5f8fdd3ea5cd14267b1d9cc7efc3d208447de8a Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:17 +0900 Subject: [PATCH 0023/1025] Add en doc --- ...separation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 38c2aea1c9..505003747d 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -174,6 +174,7 @@ end if RUBY_VERSION < "2.7" * * * * * 自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 +--- {% highlight ruby %} def target(*args) From bdd3514fe2b0a6a4e52ae311b93d39f462f9ac87 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Wed, 22 Jan 2020 12:35:47 +0900 Subject: [PATCH 0024/1025] Translate "Separation of positional and keyword arguments in Ruby 3.0" --- ...paration-of-positional-and-keyword-arguments-in-ruby-3-0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 505003747d..234c6671db 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -13,6 +13,8 @@ lang: ja この文書では便宜上、必須引数、オプション引数、rest引数、後置引数(つまり、キーワード引数とブロック引数以外の引数)をまとめて「位置引数」と呼びます。 +Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 + Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7で警告を表示します。以下のいずれかの警告が表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated` @@ -174,7 +176,6 @@ end if RUBY_VERSION < "2.7" * * * * * 自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 ---- {% highlight ruby %} def target(*args) From d1d39723a179d9f0e97329bb48786981c8147c54 Mon Sep 17 00:00:00 2001 From: hachi8833 Date: Thu, 30 Jan 2020 16:49:40 +0900 Subject: [PATCH 0025/1025] Fix untranslated lines --- ...eparation-of-positional-and-keyword-arguments-in-ruby-3-0.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 234c6671db..38c2aea1c9 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -13,8 +13,6 @@ lang: ja この文書では便宜上、必須引数、オプション引数、rest引数、後置引数(つまり、キーワード引数とブロック引数以外の引数)をまとめて「位置引数」と呼びます。 -Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7でwarningを表示します。以下のいずれかのwarningが表示される場合は、コードのアップデートが必要です。 - Ruby 3.0では、位置引数とキーワード引数が分離されます。Ruby 3.0で変更される振る舞いはRuby 2.7で警告を表示します。以下のいずれかの警告が表示される場合は、コードのアップデートが必要です。 * `Using the last argument as keyword parameters is deprecated` From 8b1e350ead504e7d804b7b44dfa2669cd56e2fab Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Mon, 29 Nov 2021 10:40:13 +0900 Subject: [PATCH 0026/1025] Added some changes that we consider to minor. --- ...ositional-and-keyword-arguments-in-ruby-3-0.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md index 38c2aea1c9..ac24a4a40e 100644 --- a/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md +++ b/ja/news/_posts/2019-12-12-separation-of-positional-and-keyword-arguments-in-ruby-3-0.md @@ -24,6 +24,7 @@ Ruby 3.0では、位置引数とキーワード引数が分離されます。Rub Ruby 3では、すべての引数を委譲するメソッドで、位置引数の他に必ずキーワード引数も明示的に委譲しなければなりません。Ruby 2.7以前の委譲の振る舞いを変えたくない場合は、`ruby2_keywords`をお使いください。詳しくは後述の「引数の委譲の扱いについて」をご覧ください。 ## よくあるケース +{: #typical-cases } 以下はもっともよくあるケースです。Hashではなくキーワードを渡すのにdouble splat演算子(`**`)を使えます。 @@ -69,6 +70,7 @@ bar({ k: 42 }) # => {:k=>42} {% endhighlight %} ## どの動作が非推奨になるか +{: #what-is-deprecated } Ruby 2では、キーワード引数が末尾のハッシュ位置引数として扱われることがあります。また、末尾のハッシュ引数がキーワード引数として扱われることもあります。 @@ -101,6 +103,7 @@ foo(k: 1) #=> {:k=>1} {% endhighlight %} ## Q: 自分のコードはRuby 2.7で動かなくなりますか? +{: #break-on-ruby-2-7 } A: たぶん動きます。 @@ -111,8 +114,10 @@ Ruby 2.7では、警告が表示される点と軽微な変更点以外を除い 非推奨の警告を無効にしたい場合は、コマンドライン引数`-W:no-deprecated`を使うか、コードに`Warning[:deprecated] = false`を追加します。 ## 引数の委譲の扱いについて +{: #delegation } ### Ruby 2.6以前の場合 +{: #delegation-ruby-2-6-or-prior } Ruby 2では、以下のように1個の`*rest`引数と1個の`&block`引数を受け付けて、この2つの引数を委譲先メソッド(以下の`target`)に渡すことで委譲メソッドを書けます。この振る舞いでは、(1つ以上の)キーワード引数も「位置引数<=>キーワード引数の自動変換」によって暗黙的に扱われます。 @@ -123,6 +128,7 @@ end {% endhighlight %} ### Ruby 3の場合 +{: #delegation-ruby-3 } 以下のようにキーワード引数を明示的に委譲する必要があります。 @@ -141,6 +147,7 @@ end {% endhighlight %} ### Ruby 2.7の場合 +{: #delegation-ruby-2-7 } 手短かに言うと、以下のように`Module#ruby2_keywords`を用い、`*args, &block`を委譲します。 @@ -155,6 +162,7 @@ end 実際、Ruby 2.7では多くの場面でこの新しい委譲のスタイルを利用できます。ただし1つ既知のエッジケースがあります。次をご覧ください。 ### Ruby 2.6 / 2.7 / 3で互換性のある委譲スタイル +{: #a-compatible-delegation } 手短かに言うと、ここも「`Module#ruby2_keywords`を使う」となります。 @@ -171,7 +179,7 @@ def ruby2_keywords(*) end if RUBY_VERSION < "2.7" {% endhighlight %} -* * * * * +--- 自分のコードがRuby 2.6以前で動かなくても構わないのであれば、Ruby 2.7で新しいスタイルを試してもよいでしょう。ほぼほぼ間違いなく動作しますが、以下のようなエッジケースを運悪く踏むこともあります。 @@ -195,10 +203,12 @@ foo({}, **{}) #=> Ruby 2.7: [{}] ({}を渡せば、キーワード引数が「 移植性がどうしても不安な場合は`ruby2_keywords`をお使いください(Ruby 2.6以前ではキーワード引数周りで膨大なエッジケースが存在していることを知っておいてください)。`ruby2_keywords`は、今後Ruby 2.6がサポート切れになったあとで削除される可能性があります。そのときになったら、キーワード引数を明示的に委譲することをおすすめします(上述のRuby 3向けのコードを参照)。 ## その他の軽微な変更点 +{: #other-minor-changes } Ruby 2.7のキーワード引数では、この他に以下の3つの軽微な変更が行われています。 ### 1\. キーワード引数で非シンボルキーを利用できるようになった +{: #other-minor-changes-non-symbol-keys } Ruby 2.6以前のキーワード引数では、シンボル形式のキーしか利用できませんでした。Ruby 2.7のキーワード引数では、以下のようにシンボル形式でないキーを利用できるようになります。 @@ -242,6 +252,7 @@ bar("key" => 42, :sym => 43) {% endhighlight %} ### 2\. double splatを付けた空ハッシュ(`**{}`)で引数を渡さないようになった +{: #other-minor-changes-empty-hash } Ruby 2.6以前は、`**empty_hash`を渡すと位置引数に空のハッシュが渡されました(`[{}]`)。Ruby 2.7以降では引数を渡さなくなります。 @@ -274,6 +285,7 @@ foo(**empty_hash) {% endhighlight %} ### 3\. キーワード引数を受け取らないことを表す構文(`**nil`)が導入される +{: #other-minor-changes-double-splat-nil } メソッド定義で`**nil`を用いることで、そのメソッドがキーワード引数を受け取らないことを明示的に示せるようになります。このメソッドを呼び出すときにキーワード引数を渡すと`ArgumentError`が表示されます(これは非互換性ではなく、新機能です)。 @@ -306,6 +318,7 @@ foo(k: 1) #=> ArgumentError: unknown keyword k {% endhighlight %} ## 自動変換を非推奨に変える理由 +{: #why-deprecated } 当初、自動変換はうまいアイデアに思われていて、多くの場合問題なく機能していました。しかし、エッジケースがあまりにも多く、これまでこの振る舞いに関するバグレポートを山のように受け取りました。 From 43feb73e0af06667ddbb9a695972fe019fc00a57 Mon Sep 17 00:00:00 2001 From: Andrias Meisyal Date: Sat, 27 Nov 2021 21:07:05 +0700 Subject: [PATCH 0027/1025] Translate CVE-2021-31810: Trusting FTP PASV responses vulnerability in Net::FTP (id) --- ...7-07-trusting-pasv-responses-in-net-ftp.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 id/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md diff --git a/id/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md b/id/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md new file mode 100644 index 0000000000..6dad71eca8 --- /dev/null +++ b/id/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md @@ -0,0 +1,40 @@ +--- +layout: news_post +title: "CVE-2021-31810: Kerentanan respons FTP PASV yang dipercaya pada Net::FTP" +author: "shugo" +translator: "meisyal" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: id +--- + +Sebuah kerentanan respons FTP PASV yang dipercaya telah ditemukan pada Net::FTP. +Kerentanan ini telah ditetapkan dengan penanda CVE +[CVE-2021-31810](https://nvd.nist.gov/vuln/detail/CVE-2021-31810). +Kami sangat merekomendasikan Anda untuk memperbarui Ruby. + +net-ftp adalah sebuah *default gem* pada Ruby 3.0.1, tetapi *gem* tersebut +memiliki masalah pengemasan. Sehingga, mohon perbarui Ruby. + +## Detail + +Sebuah FTP *server* yang berbahaya dapat menggunakan respons PASV untuk +mengelabui Net::FTP dengan menghubungkan kembali ke sebuah alamat IP dan *port* +yang diberikan. Ini berpotensi membuat Net::FTP menguraikan informasi *service* +yang seharusnya privat dan tidak boleh terbuka (contohnya, penyerang melakukan +*port scan* dan *service banner extraction*). + +## Versi Terimbas + +* Rangkaian Ruby 2.6: 2.6.7 dan sebelumnya +* Rangkaian Ruby 2.7: 2.7.3 dan sebelumnya +* Rangkaian Ruby 3.0: 3.0.1 dan sebelumnya + +## Rujukan + +Terima kasih kepada [Alexandr Savca](https://hackerone.com/chinarulezzz) yang +telah melaporkan kerentanan ini. + +## Riwayat + +* Semula dipublikasikan pada 2021-07-07 09:00:00 UTC From 568fbdc9322ab3d5f91c9938af05a890841ead65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Thu, 2 Dec 2021 09:48:22 -0500 Subject: [PATCH 0028/1025] Translation of Ruby 3.1.0-preview1 releases (es) (#2736) --- ...2021-11-09-ruby-3-1-0-preview1-released.md | 259 ++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 es/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md diff --git a/es/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md b/es/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md new file mode 100644 index 0000000000..6bbecd9013 --- /dev/null +++ b/es/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md @@ -0,0 +1,259 @@ +--- +layout: news_post +title: "Publicado Ruby 3.1.0 versión previa 1" +author: "naruse" +translator: vtamara +date: 2021-11-09 00:00:00 +0000 +lang: es +--- + +Nos complace anunciar la publicación de Ruby {{ release.version }}. + +{% assign release = site.data.releases | where: "version", "3.1.0-preview1" | first %} + + +## YJIT: Nuevo compilador experimental JIT en-proceso + +Ruby 3.1 incorpora YJIT, un nuevo compilador JIT en-proceso desarrollado +por Shopify. + +Desde que [Ruby 2.6 introdujo MJIT en 2018](https://www.ruby-lang.org/es/news/2018/12/25/ruby-2-6-0-released/), +su desempeño ha mejorado significativamente, y finalmente +[alcanzamos Ruby3x3 el año pasado](https://www.ruby-lang.org/es/news/2020/12/25/ruby-3-0-0-released/). +Pero aún cuando Optcarrot ha demostrado un impresionante aumento de velocidad, +el JIT no ha beneficiado aplicaciones de negocios del mundo real. + +Recientemente Shopify contribuyó muchas mejoras a Ruby para aumentar la +velocidad de su aplicación Rails. +YJIT es una contribución importante y busca mejorar el desempeño de +aplicaciones rails. + +Mientras MJIT es un compilador JIT basado-en-métodos y usa un +compilador de C externo, YJIT usa Versiones de Bloques Básicos e +incluye un compilador JIT. Con Versiones de Bloques Básicos Perezosa +(Lazy Basic Block Versioning - LBBV), que primero compilan el comienzo de +un método e incrementalmente compila el resto a medida que el tipo de +los argumentos y variables se determina dinámicamente. Ver una introducción +detallada en +[YJIT: a basic block versioning JIT compiler for CRuby](https://dl.acm.org/doi/10.1145/3486606.3486781). + +Con esta tecnología, YJIT alcanza tanto un tiempo de calentamiento rápido como +mejoras en desempeño en la mayoría de software del mundo-real, hasta +22% en railsbench, 39% en liquid-render. + + + +YJIT es aún una características experimental, y como tal, +está deshabilitado de manera predeterminada. Si quiere usarlo, +especifique la opción `--yjit` en la línea de ordenes que habilita +YJIT. Por ahora está limitado a macOS & Linux sobre plataformas +x86-64. + +* https://bugs.ruby-lang.org/issues/18229 +* https://shopify.engineering/yjit-just-in-time-compiler-cruby +* https://www.youtube.com/watch?v=PBVLf3yfMs8 + +## Gema debug: Un nuevo depurador + +Se incluye un nuevo depurador [debug.gem](https://github.com/ruby/debug). +debug.gem es una implementación de un depurador rápido que provee muchas +características tales como depuración remota, REPL con colores, integración +con IDE (VSCode) entre otras. +Remplaza la librería estándar `lib/debug.rb`. + +## error_highlight: Localización de errores afinada en las trazas + +Se ha incluido un gema con Ruby, error_highlight. Proporciona +localización afinada de errores en la traza: + +``` +$ ruby prueba.rb +prueba.rb:1:in `
': undefined method `time' for 1:Integer (NoMethodError) + +1.time {} + ^^^^^ +Did you mean? times +``` + +Esta gema está habilitada de manera predeterminada. Puede deshabilitarla +desde la línea de ordenes con la opción `--disable-error_highlight`. +Ver detalles en [el repositorio](https://github.com/ruby/error_highlight). + +## Mejoras a Irb + +Se describirán en la siguiente versión previa. + +## Otras características nuevas y notables + +### Lenguaje + +* Pueden omitirse valores en literales de diccionarios y en argumentos de + palabra reservada [Feature #14579] + * `{x:, y:}` es azúcar sintáctica para `{x: x, y: y}`. + * `foo(x:, y:)` es azúcar sintáctica para `foo(x: x, y: y)`. + +* En reconocimiento de patrones el operador pin ahora toma una + expresión [Feature #17411] + +```ruby +Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a +#=> [[3, 5], [5, 7], [11, 13]] +``` + + +### RBS + +RBS es un lenguaje para describir la estructura de programas Ruby. +Ver detalles en [el repositorio](https://github.com/ruby/rbs). + +Actualizaciones desde Ruby 3.0.0: + +* se introduce `rbs collection` para administrar RBSs de gemas. + [doc](https://github.com/ruby/rbs/blob/master/docs/collection.md) +* Se han añadido/actualizado muchas características incorporadas y de + la librería estándar. +* Incluye soluciones a muchas fallas, así como mejoras de desempeño. + +Ver más informaciń en [el archivo CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md). + +### TypeProf + +TypeProf es un analizador de tipos estático para Ruby. Genera un prototipo +en RBS a partir de código Ruby sin anotaciones de tipos. Ver detalles en +[el documento](https://github.com/ruby/typeprof/blob/master/doc/doc.md). + +Actualizaciones desde Ruby 3.0.0: + +* Se ha implementado [soporte experimental para IDE](https://github.com/ruby/typeprof/blob/master/doc/ide.md). +* Muchas correcciones a fallas y mejoras de desempeño. + +## Mejoras de desempeño + +* MJIT + * Para cargas de trabajo como Rails, se cambia `--jit-max-cache` de 100 + a 10000. + El compilador JIT ya no se salta la compilación de métodos con menos de + 1000 instrucciones. + * Para soportar Zeitwerk de Rails, el código compilado con JIT ya no + se cancela cuando se habilita un TracePoint para eventos de clase. + +## Otros cambios notables desde 3.0 + +* Reconocimiento de patrones en una línea, e.g., `ary => [x, y, z]`, ya no es + experimental. +* Se ha cambiado levemente el orden de evaluación de asignaciones múltiples. + [[Bug #4443]] + * `foo[0], bar[0] = baz, qux` era evaluado en el orden `baz`, `qux`, `foo`, + y después `bar` en Ruby 3.0. En Ruby 3.1, se evalúa en el orden + `foo`, `bar`, `baz`, y después `qux`. +* Localización de ancho variable: Cadenas (experimental) + [[Falla #18239]](https://bugs.ruby-lang.org/issues/18239) + +### Actualizaciones a la librería estándar + +* Se actualizaron algunas librerías estándar + * RubyGems + * Bundler + * RDoc 6.4.0 + * ReLine + * JSON 2.6.0 + * Psych 4.0.2 + * FileUtils 1.6.0 + * Fiddle + * StringIO 3.0.1 + * IO::Console 0.5.9 + * IO::Wait 0.2.0 + * CSV + * Etc 1.3.0 + * Date 3.2.0 + * Zlib 2.1.1 + * StringScanner + * IpAddr + * Logger 1.4.4 + * OStruct 0.5.0 + * Irb + * Racc 1.6.0 + * Delegate 0.2.0 + * Benchmark 0.2.0 + * CGI 0.3.0 + * Readline(C-ext) 0.1.3 + * Timeout 0.2.0 + * YAML 0.2.0 + * URI 0.11.0 + * OpenSSL + * DidYouMean + * Weakref 0.1.1 + * Tempfile 0.1.2 + * TmpDir 0.1.2 + * English 0.7.1 + * Net::Protocol 0.1.2 + * Net::Http 0.2.0 + * BigDecimal + * OptionParser 0.2.0 + * Set + * Find 0.1.1 + * Rinda 0.1.1 + * Erb + * NKF 0.1.1 + * Base64 0.1.1 + * OpenUri 0.2.0 + * SecureRandom 0.1.1 + * Resolv 0.2.1 + * Resolv::Replace 0.1.0 + * Time 0.2.0 + * PP 0.2.1 + * Prettyprint 0.1.1 + * Drb 2.1.0 + * Pathname 0.2.0 + * Digest 3.1.0.pre2 + * Un 0.2.0 +* Se actualizaron las siguientes gemas incluidas en Ruby + * minitest 5.14.4 + * power_assert 2.0.1 + * rake 13.0.6 + * test-unit 3.5.0 + * rbs 1.6.2 + * typeprof 0.20.0 +* Las siguientes gemas por omisión ahora son ahora gemas incluidas en Ruby. + * net-ftp + * net-imap + * net-pop + * net-smtp + * matrix + * prime + +Ver más detalles en +[NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md) +o [en la bitácora de cambios](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}). + +Con esos cambios, [{{ release.stats.files_changed }} archivos cambiados, {{ release.stats.insertions }} inserciones(+), {{ release.stats.deletions }} eliminaciones (-)](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}#file_bucket) +desde Ruby 3.0.0! + +## Descargas + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Qué es Ruby + +Ruby fue desarrollado inicialmente pof Matz (Yukihiro Matsumoto) en 1993, +y ahora es desarrollado como Código Abierto. Corre en múltiples +plataformas y se usa en todo el mundo especialmente para desarrollo web. From 8582d2af9bc328a6d90d11b44daaf48e169f18ed Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:40:51 +0900 Subject: [PATCH 0029/1025] Japanese translation of "CVE-2021-31810: Trusting FTP PASV responses vulnerability in Net::FTP" Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md) to ja. --- ...7-07-trusting-pasv-responses-in-net-ftp.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ja/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md diff --git a/ja/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md b/ja/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md new file mode 100644 index 0000000000..6e122de845 --- /dev/null +++ b/ja/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md @@ -0,0 +1,35 @@ +--- +layout: news_post +title: "CVE-2021-31810: Net::FTP における信頼性のある FTP PASV 応答の脆弱性について" +author: "shugo" +translator: "jinroq" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: ja +--- + +信頼性のある FTP PASV 応答の脆弱性が Net::FTP で発見されました。 +この脆弱性は [CVE-2021-31810](https://nvd.nist.gov/vuln/detail/CVE-2021-31810) として登録されています。 +Ruby をアップグレードすることを強く推奨します。 + +net-ftp は Ruby 3.0.1 の デフォルト gem ですが、パッケージ化の問題があるため、Ruby 自体をアップグレードしてください。 + +## 詳細 + +悪意のある FTP サーバーが、PASV 応答を利用して Net::FTP を偽装し、特定の IP アドレスとポートに接続し直す可能性があります。 +これにより Net::FTP は本来では抽出できない非公開なサービスに関する情報を抽出する可能性があります +(例: 攻撃者はポートスキャンやサービスバナーの抽出を実行できます)。 + +## 影響を受けるバージョン + +* Ruby 2.6 系列: 2.6.7 およびそれ以前のバージョン +* Ruby 2.7 系列: 2.7.3 およびそれ以前のバージョン +* Ruby 3.0 系列: 3.0.1 およびそれ以前のバージョン + +## クレジット + +この脆弱性情報は、[Alexandr Savca](https://hackerone.com/chinarulezzz) 氏によって報告されました。 + +## 更新履歴 + +* 2021-07-07 18:00:00 (JST) 初版 From 85b21c3e53f54cef7d0b7f8f156c0f708c950bb4 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Thu, 25 Nov 2021 17:52:06 +0900 Subject: [PATCH 0030/1025] Japanese translation of "CVE-2021-41816: Buffer Overrun in CGI.escape_html" Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md) to ja. --- ...errun-in-cgi-escape_html-cve-2021-41816.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md diff --git a/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md b/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md new file mode 100644 index 0000000000..b6712c7c3f --- /dev/null +++ b/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md @@ -0,0 +1,39 @@ +--- +layout: news_post +title: "CVE-2021-41816: CGI.escape_html 内のバッファオーバーラン" +author: "mame" +translator: "jinroq" +date: 2021-11-24 12:00:00 +0000 +tags: security +lang: ja +--- + +A buffer overrun vulnerability was discovered in CGI.escape_html. +This vulnerability has been assigned the CVE identifier [CVE-2021-41816](https://nvd.nist.gov/vuln/detail/CVE-2021-41816). +We strongly recommend upgrading Ruby. +CGI.escape_html 内のバッファオーバーランの脆弱性が発見されました。 +この脆弱性は、[CVE-2021-41816](https://nvd.nist.gov/vuln/detail/CVE-2021-41816)として登録されています。 +Ruby をアップグレードすることを強く推奨します。 + +## 詳細 + +`long` 型が 4 バイトかかるプラットフォーム(典型的なものは Windows)で非常に大きな文字列(700 MB 以上)を `CGI.escape_html` に渡すと、バッファオーバーフローを引き起こす脆弱性があります。 + +cgi gem をバージョン 0.3.1, 0.2.1, 0.1.1 もしくはこれら以上のバージョンに更新してください。`gem update cgi` を使用して更新できます。bundler を使用している場合は、 `Gemfile` に `gem "cgi", "> = 0.3.1"` を追加してください。 +または、Rubyを 2.7.5 または 3.0.3 に更新してください。 + +この問題は Ruby 2.7 以降で発見されたので、Ruby 2.6 でバンドルされている cgi バージョンには脆弱性はありません。 + +## 影響を受けるバージョン + +* cgi gem 0.1.0 以前(Ruby 2.7.5 より前にバンドルされている Ruby 2.7 系列) +* cgi gem 0.2.0 以前(Ruby 3.0.3 より前にバンドルされている Ruby 3.0 系列) +* cgi gem 0.3.0 以前 + +## クレジット + +この脆弱性情報は、[chamal](https://hackerone.com/chamal) 氏によって報告されました。 + +## 更新履歴 + +* 2021-11-24 21:00:00 (JST) 初版 From cf989664e27d38c7ed1c38c6548d8a32523721e3 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 12:46:24 +0900 Subject: [PATCH 0031/1025] Japanese translation of "Ruby 3.1.0 Preview 1 Released" Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md) to ja. --- ...2021-11-09-ruby-3-1-0-preview1-released.md | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md diff --git a/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md b/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md new file mode 100644 index 0000000000..bcd1ca2733 --- /dev/null +++ b/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md @@ -0,0 +1,210 @@ +--- +layout: news_post +title: "Ruby 3.1.0 Preview 1 リリース" +author: "naruse" +translator: "jinroq" +date: 2021-11-09 00:00:00 +0000 +lang: ja +--- + +Ruby 3.1 に向けてフィードバックを得るためのリリースである、Ruby 3.1.0-preview1 が公開されました。 + +{% assign release = site.data.releases | where: "version", "3.1.0-preview1" | first %} + +## YJIT: 新しいインプロセス JIT コンパイラ (experimental) + +Ruby 3.1 には、Shopify 社が開発した新しいインプロセス JIT コンパイラである YJIT をマージしています。 + +[2018 年に Ruby 2.6 が MJIT を導入](https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/)して以降、パフォーマンスは大幅に向上し、ついに[昨年 Ruby3x3 を達成しました](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/)。しかし、この JIT は Optcarrot では目覚ましい速度改善を示したものの、実世界のプロダクトで運用するには厳しいものでした。 + +近年 Shopify 社は Rails アプリケーションを高速化するために Ruby へ多くの改善をしてくれました。その中でも YJIT は重要な貢献であり、また、Rails アプリケーションのパフォーマンス向上を目的としています。 + +MJIT はメソッドベースの JIT コンパイラであり、外部 C コンパイラを使用します。一方、YJIT は Basic Block Versioning を使用し、その中に JIT コンパイラを含みます。 Lazy Basic Block Versioning(LBBV)では、最初にメソッドの先頭をコンパイルし、引数と変数の型が動的に決定されると、残りをインクリメンタルにコンパイルします。詳細な概要については [YJIT: a basic block versioning JIT compiler for CRuby](https://dl.acm.org/doi/10.1145/3486606.3486781) を参照してください。 + +この技術により、YJIT は実世界の多くのプロダクトで高速な起動時間とパフォーマンス向上の両方を実現しています。railsbench 上で 22%、liquid-render 上で 39% の改善を実現しています。 + + + +YJIT はまだ実験的な機能であるため、デフォルトでは無効になっています。使用するにはコマンドラインオプション `--yjit` を指定して YJIT を有効にします。また YJIT が仕様できる環境は、現時点では x86-64 プラットフォーム搭載の macOS および Linux に限定されています。 + +* [https://bugs.ruby-lang.org/issues/18229](https://bugs.ruby-lang.org/issues/18229) +* [https://shopify.engineering/yjit-just-in-time-compiler-cruby](https://shopify.engineering/yjit-just-in-time-compiler-cruby) +* [https://www.youtube.com/watch?v=PBVLf3yfMs8](https://www.youtube.com/watch?v=PBVLf3yfMs8) + +## debug gem: 新しいデバッガ + +新しいデバッガ [debug.gem](https://github.com/ruby/debug) がバンドルされています。 debug.gem は高速なデバッガであり、リモートデバッグ、色付き REPL、IDE integration(VSCode)など多くの機能を提供します。これは標準添付ライブラリの `lib/debug.rb` に置き換えられます。 + +## error_highlight: バックトレース内でさらに詳細なエラー箇所を示す機能 + +組み込み gem である error_highlight が導入されました。バックトレース内でさらに詳細なエラー箇所を示すことができます: + +``` +$ ruby test.rb +test.rb:1:in `
': undefined method `time' for 1:Integer (NoMethodError) + +1.time {} + ^^^^^ +Did you mean? times +``` + +この gem はデフォルトで有効になっています。コマンドラインオプション `--disable-error_highlight` を使用して無効にできます。詳細は[リポジトリ](https://github.com/ruby/error_highlight)を参照してください。 + +## Irb の改善 + +次の preview 版で説明します。 + +## その他の主要な新機能 + +### 言語仕様 + +* ハッシュリテラルとキーワード引数の値は省略できます [Feature #14579] + * `{x:, y:}` は `{x: x, y: y}` の糖衣構文です + * `foo(x:, y:)` は `foo(x: x, y: y)` の糖衣構文です + +* パターンマッチングのピン演算子が式を受け取るようになりました [Feature #17411] + +```ruby +Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a +#=> [[3, 5], [5, 7], [11, 13]] +``` + +### RBS + +RBS は Ruby プログラムの構造を記述するための言語です。詳細は[リポジトリ](https://github.com/ruby/rbs)を参照してください。 + +Ruby 3.0.0 からの変更点: + +* gem の RBS を管理する `rbs collection` が導入されています [[doc]](https://github.com/ruby/rbs/blob/master/docs/collection.md) +* 組み込みライブラリおよび標準添付ライブラリの多くのシグネチャが追加/更新されています +* 多くのバグ修正とパフォーマンスの改善も含まれています + +詳細は [CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md) を参照してください。 + +### TypeProf + +TypeProf は Ruby の静的型解析器です。型注釈のない Ruby コードから RBS のプロトタイプを生成します。詳細は[ドキュメント](https://github.com/ruby/typeprof/blob/master/doc/doc.md)を参照してください。 + +Ruby 3.0.0 からの変更点: + +* [IDE サポート](https://github.com/ruby/typeprof/blob/master/doc/ide.md)が実装されました (Experimental) +* 多くのバグ修正とパフォーマンスの改善も含まれています + +## パフォーマンスの改善 + +* MJIT + * Rails のようなワークロードのために、`--jit-max-cache` のデフォルト値を 100 から 10000 に変更しています。 + JIT コンパイラは 1000 命令列長より長いメソッドのコンパイルをスキップしなくなりました + * Rails の Zeitwerk モードをサポートするために、クラスイベントで TracePoint が有効になっている場合に JIT コンパイルされたコードをキャンセルしなくなりました + +## その他の注目すべき 3.0 からの変更点 + +* 1 行パターンマッチ(例: `ary => [x, y, z]`)が experimental ではなくなりました +* 多重代入の評価順序が若干変更されました [[Bug #4443]](https://bugs.ruby-lang.org/issues/4443) + * Ruby 3.0では `foo[0], bar[0] = baz, qux` は `baz`, `qux`,`foo`, `bar` の順に評価されていました。Ruby 3.1 からは `foo`,`bar`, `baz`,`qux` の順に評価されるようになります +* 文字列の可変幅割り当て (experimental) [[Bug #18239]](https://bugs.ruby-lang.org/issues/18239) + +### 標準添付ライブラリの更新 + +* いくつかの標準添付ライブラリが更新されています + * RubyGems + * Bundler + * RDoc 6.4.0 + * ReLine + * JSON 2.6.0 + * Psych 4.0.2 + * FileUtils 1.6.0 + * Fiddle + * StringIO 3.0.1 + * IO::Console 0.5.9 + * IO::Wait 0.2.0 + * CSV + * Etc 1.3.0 + * Date 3.2.0 + * Zlib 2.1.1 + * StringScanner + * IpAddr + * Logger 1.4.4 + * OStruct 0.5.0 + * Irb + * Racc 1.6.0 + * Delegate 0.2.0 + * Benchmark 0.2.0 + * CGI 0.3.0 + * Readline(C-ext) 0.1.3 + * Timeout 0.2.0 + * YAML 0.2.0 + * URI 0.11.0 + * OpenSSL + * DidYouMean + * Weakref 0.1.1 + * Tempfile 0.1.2 + * TmpDir 0.1.2 + * English 0.7.1 + * Net::Protocol 0.1.2 + * Net::Http 0.2.0 + * BigDecimal + * OptionParser 0.2.0 + * Set + * Find 0.1.1 + * Rinda 0.1.1 + * Erb + * NKF 0.1.1 + * Base64 0.1.1 + * OpenUri 0.2.0 + * SecureRandom 0.1.1 + * Resolv 0.2.1 + * Resolv::Replace 0.1.0 + * Time 0.2.0 + * PP 0.2.1 + * Prettyprint 0.1.1 + * Drb 2.1.0 + * Pathname 0.2.0 + * Digest 3.1.0.pre2 + * Un 0.2.0 +* 以下のバンドルされた gems が更新されています + * minitest 5.14.4 + * power_assert 2.0.1 + * rake 13.0.6 + * test-unit 3.5.0 + * rbs 1.6.2 + * typeprof 0.20.0 +* 以下のデフォルト gems がバンドルされた gem になりました + * net-ftp + * net-imap + * net-pop + * net-smtp + * matrix + * prime + +詳細は [NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md) か [commit logs](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}) を参照してください。 + +なお、こうした変更により、Ruby 3.0.0 以降では [{{ release.stats.files_changed }} 個のファイルに変更が加えられ、 {{ release.stats.insertions }} 行の追加と {{ release.stats.deletions }} 行の削除が行われました](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}#file_bucket)! + +## ダウンロード + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Ruby とは + +Ruby はまつもとゆきひろ(Matz)によって 1993 年に開発が始められ、今もオープンソースソフトウェアとして開発が続けられています。 +Ruby は様々なプラットフォームで動き、世界中で、特に Web アプリケーション開発のために使われています。 From cd5d083f793f69db198d73e21f07cc910bcd9d4a Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 21:26:16 +0900 Subject: [PATCH 0032/1025] Fixed a bug Fixed a bug that disturbed `release.version` from being displayed. --- ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md b/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md index bcd1ca2733..125aed23f2 100644 --- a/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md +++ b/ja/news/_posts/2021-11-09-ruby-3-1-0-preview1-released.md @@ -7,10 +7,10 @@ date: 2021-11-09 00:00:00 +0000 lang: ja --- -Ruby 3.1 に向けてフィードバックを得るためのリリースである、Ruby 3.1.0-preview1 が公開されました。 - {% assign release = site.data.releases | where: "version", "3.1.0-preview1" | first %} +Ruby 3.1 に向けてフィードバックを得るためのリリースである、Ruby {{ release.version }} が公開されました。 + ## YJIT: 新しいインプロセス JIT コンパイラ (experimental) Ruby 3.1 には、Shopify 社が開発した新しいインプロセス JIT コンパイラである YJIT をマージしています。 From 36bbdaa59d6a658c4bdcf51ab8575e0da8b070fe Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 3 Dec 2021 17:06:26 +0900 Subject: [PATCH 0033/1025] Removed unnecessary English text. --- ...1-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md b/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md index b6712c7c3f..6414233097 100644 --- a/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md +++ b/ja/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md @@ -8,9 +8,6 @@ tags: security lang: ja --- -A buffer overrun vulnerability was discovered in CGI.escape_html. -This vulnerability has been assigned the CVE identifier [CVE-2021-41816](https://nvd.nist.gov/vuln/detail/CVE-2021-41816). -We strongly recommend upgrading Ruby. CGI.escape_html 内のバッファオーバーランの脆弱性が発見されました。 この脆弱性は、[CVE-2021-41816](https://nvd.nist.gov/vuln/detail/CVE-2021-41816)として登録されています。 Ruby をアップグレードすることを強く推奨します。 From b9a2cab013eaeac40e2295b92485b2a7b6b0d350 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 15:21:54 +0900 Subject: [PATCH 0034/1025] Translate "CVE-2021-32066: A StartTLS stripping vulnerability in Net::IMAP" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md) to ja. --- ...21-07-07-starttls-stripping-in-net-imap.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md diff --git a/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md new file mode 100644 index 0000000000..6d2f0d0343 --- /dev/null +++ b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -0,0 +1,34 @@ +--- +layout: news_post +title: "CVE-2021-32066: Net::IMAP 内の StartTLS ストリッピングの脆弱性について" +author: "shugo" +translator: "jinroq" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: ja +--- + +Net::IMAP 内の StartTLS ストリッピングに脆弱性が発見されました。 +この脆弱性は [CVE-2021-32066](https://nvd.nist.gov/vuln/detail/CVE-2021-32066) として登録されています。 +Ruby をアップグレードすることを強く推奨します。 + +net-imap は Ruby 3.0.1 の デフォルト gem ですが、パッケージ化の問題があるため、Ruby 自体をアップグレードしてください。 + +## 詳細 + +Net::IMAP は、StartTLS が不明な応答で失敗した場合に例外を発生させません。これにより、中間者攻撃者がクライアントとレジストリ間のネットワークの場所を利用して StartTLS コマンドをブロックできる可能性があります。つまり、中間者攻撃者が TLS 保護をバイパスできる可能性があります。 +これは「StartTLS ストリッピング攻撃」とも呼ばれています。 + +## 影響を受けるバージョン + +* Ruby 2.6 系列: 2.6.7 およびそれ以前のバージョン +* Ruby 2.7 系列: 2.7.3 およびそれ以前のバージョン +* Ruby 3.0 系列: 3.0.1 およびそれ以前のバージョン + +## クレジット + +この脆弱性情報は、[Alexandr Savca](https://hackerone.com/chinarulezzz) 氏によって報告されました。 + +## 更新履歴 + +* 2021-07-07 18:00:00 (JST) 初版 From 0e5e25f8e1e46d121cc14b0936a835696d9db50f Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 16:04:13 +0900 Subject: [PATCH 0035/1025] Translate "CVE-2021-28965: XML round-trip vulnerability in REXML" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md) to ja. --- ...p-vulnerability-in-rexml-cve-2021-28965.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md diff --git a/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md new file mode 100644 index 0000000000..65589d9ebe --- /dev/null +++ b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -0,0 +1,47 @@ +--- +layout: news_post +title: "CVE-2021-28965: REXML 内の XML ラウンドトリップの脆弱性について" +author: "mame" +translator: "jinroq" +date: 2021-04-05 12:00:00 +0000 +tags: security +lang: ja +--- + +Ruby にバンドルされている REXML gem 内の XML ラウンドトリップに脆弱性が発見されました。 +この脆弱性は [CVE-2021-28965](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28965) として登録されています。 +REXML gem をアップグレードすることを強く推奨します。 + +## 詳細 + +加工された XML ドキュメントをパーシングおよびシリアル化する場合、REXML gem(Ruby にバンドルされているものを含む)は、元のドキュメントとは構造が異なる誤った XML ドキュメントを生成する可能性があります。 +この問題の影響はコンテキストによって大きく異なりますが、REXML を使用している一部のプログラムでは脆弱性が生じる可能性があります。 + +REXML gem をバージョン 3.2.5 以降に更新してください。 + +Ruby 2.6 以降を使用している場合: + +* Ruby 2.6.7、2.7.3、もしくは 3.0.1 を使ってください +* または `gem update rexml` で更新することもできます。bundler を使用している場合は、`Gemfile` に `gem "rexml", ">= 3.2.5"` を追加してください + +Ruby 2.5.8 以前を使用している場合: + +* Ruby 2.5.9 を使ってください +* Ruby 2.5.8 以前では `gem update rexml` を実行できません +* Ruby 2.5 系列は現在 EOL であるため、Ruby を 2.6.7 以降に可能な限り早く更新することを検討してください + +## 影響を受けるバージョン + +* Ruby​​ 2.5.8 以前(このバージョンでは `gem update rexml` を実行できません。) +* Ruby​​ 2.6.6 以前 +* Ruby​​ 2.7.2 以前 +* Ruby​​ 3.0.0 +* REXML gem 3.2.4 以前 + +## クレジット + +この脆弱性情報は [Juho Nurminen](https://hackerone.com/jupenur) 氏によって報告されました。 + +## 更新履歴 + +* 2021-04-05 21:00:00 (JST) 初版 From 70f0285ff7ba3b5708f431ef92dab669f939d023 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 16:52:26 +0900 Subject: [PATCH 0036/1025] Translate "CVE-2021-28966: Path traversal in Tempfile on Windows" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md) to ja. --- ...ath-traversal-on-windows-cve-2021-28966.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ja/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md diff --git a/ja/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md b/ja/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md new file mode 100644 index 0000000000..95321df7ee --- /dev/null +++ b/ja/news/_posts/2021-04-05-tempfile-path-traversal-on-windows-cve-2021-28966.md @@ -0,0 +1,36 @@ +--- +layout: news_post +title: "CVE-2021-28966: Windows 版 Tempfile 内のパストラバーサルについて" +author: "mame" +translator: "jinroq" +date: 2021-04-05 12:00:00 +0000 +tags: security +lang: ja +--- + +Windows 版 Ruby にバンドルされている tmpdir ライブラリには、意図しないディレクトリを作成してしまう脆弱性が発見されました。 +また、Windows 版 Ruby にバンドルされている tempfile ライブラリは、内部で tmpdir を使用しているため同様の脆弱性があります。 +この脆弱性は [CVE-2021-28966](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28966) として登録されています。 + +## 詳細 + +tmpdir ライブラリで導入された `Dir.mktmpdir` メソッドは、第一引数に作成するディレクトリ名のプレフィックスとサフィックスを受け取ることができます。 +プレフィックスには相対ディレクトリ指定子 `"..\\"` を含めることができるため、このメソッドは任意のディレクトリを対象にすることができます。 +したがって、スクリプトが外部入力をプレフィックスとして受け取り、対象のディレクトリに不適切なアクセス許可がある、もしくは、ruby プロセスに不適切な権限がある場合に、攻撃者は任意のディレクトリに対してディレクトリやファイルを作成することができます。 + +同じ脆弱性が [CVE-2018-6914](https://www.ruby-lang.org/en/news/2018/03/28/unintentional-file-and-directory-creation-with-directory-traversal-cve-2018-6914/) として登録されていますが、Windows 版の対応が不十分でした。 + +影響を受けるバージョンの Ruby を利用している全ユーザーは、すぐにアップグレードする必要があります。 + +## 影響を受けるバージョン + +* Ruby 2.7.2 以前 +* Ruby 3.0.0 + +## クレジット + +この脆弱性情報は [Bugdiscloseguys](https://hackerone.com/bugdiscloseguys) 氏によって報告されました。 + +## 更新履歴 + +* 2021-04-05 21:00:00 (JST) 初版 From a6169206b4d5b1cad122b3225396e07ccc1ce542 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Fri, 26 Nov 2021 18:23:23 +0900 Subject: [PATCH 0037/1025] Translate "CVE-2020-25613: Potential HTTP Request Smuggling Vulnerability in WEBrick" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md) to ja. --- ...9-http-request-smuggling-cve-2020-25613.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ja/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md diff --git a/ja/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md b/ja/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md new file mode 100644 index 0000000000..bc0fdc11fe --- /dev/null +++ b/ja/news/_posts/2020-09-29-http-request-smuggling-cve-2020-25613.md @@ -0,0 +1,38 @@ +--- +layout: news_post +title: "CVE-2020-25613: WEBrick 内の潜在的な HTTP リクエストスマグリングの脆弱性について " +author: "mame" +translator: "jinroq" +date: 2020-09-29 06:30:00 +0000 +tags: security +lang: ja +--- + +WEBrick 内で潜在的な HTTP リクエストスマグリングの脆弱性が発見されました。 +この脆弱性は [CVE-2020-25613](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-25613) として登録されています。 +webrick gem をアップグレードすることを強く推奨します。 + +## 詳細 + +WEBrick は、無効な Transfer-Encoding ヘッダーに対して寛容すぎました。 +これは WEBrick と一部の HTTP プロキシサーバー間で一貫性のない解釈が発生し、攻撃者が HTTP リクエストを”スマグリング(smuggle)”する可能性があります。 +詳細は [CWE-444](https://cwe.mitre.org/data/definitions/444.html) を参照してください。 + +webric gem を 1.6.1 以降に更新してください。 +`gem update webrick` を実行すれば更新できます。 +bundler を使用している場合は、`Gemfile` に `gem "webrick", ">= 1.6.1"` を追加してください。 + +## 影響を受けるバージョン + +* webrick gem 1.6.0 以前 +* Ruby 2.7.1 以前のバージョンでバンドルされた webrick +* Ruby 2.6.6 以前のバージョンでバンドルされた webrick +* Ruby 2.5.8 以前のバージョンでバンドルされた webrick + +## クレジット + +この脆弱性情報は [piao](https://hackerone.com/piao) 氏によって報告されました。 + +## 更新履歴 + +* 2020-09-29 15:30:00 (JST) 初版 From 0771b94d4a43f2caf6afe0d6b2d6cd8632afb1b4 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 27 Nov 2021 18:50:14 +0900 Subject: [PATCH 0038/1025] Translate "Dispute of Vulnerability CVE-2014-2734" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md) to ja. --- ...-dispute-of-vulnerability-cve-2014-2734.md | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ja/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md diff --git a/ja/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md b/ja/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md new file mode 100644 index 0000000000..4fab485093 --- /dev/null +++ b/ja/news/_posts/2014-05-09-dispute-of-vulnerability-cve-2014-2734.md @@ -0,0 +1,75 @@ +--- +layout: news_post +title: "脆弱性 CVE-2014-2734 の争点について" +author: "emboss" +translator: "jinroq" +date: 2014-05-09 05:33:54 +0000 +tags: security +lang: ja +--- + +[CVE-2014-2734](http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-2734) として登録されている脆弱性について、「Ruby でも起こりうるのではないか」という報告を受けました。 +結論から書くと、以下に記載する詳細な分析の結果、Ruby に脆弱性があるとは**考えていません**。 + +この脆弱性により、攻撃者は証明書の署名を変更して任意のルート証明書を偽造し、証明書のオリジナルの秘密鍵を攻撃者が選択した秘密鍵に都合よく置き換える可能性があります。 + +## コンセプトの実証 + +以下は CVE-2014-2734 の分析です。オリジナルの PoC を縮小させることができました。これはコンセプトの実証の本質を捉えていると考えられます。 + +{% highlight ruby %} +require 'openssl' + +forge_key = OpenSSL::PKey::RSA.new(2048) +raw_certificate = File.read("arbitrary.cer") +cert = OpenSSL::X509::Certificate.new(raw_certificate) +resigned_cert = cert.sign(spoof, OpenSSL::Digest::SHA1.new) + +resigned_cert.verify(key) #=> true +{% endhighlight %} + +`X509Certificate#verify` が `true` を返してくることに驚くかもしれません。 +オリジナルの証明書には `forge_key` の公開鍵とは異なるオリジナルの公開鍵を指す[サブジェクト公開鍵情報](http://tools.ietf.org/html/rfc5280#section-4.1.2.7)が含まれている場合があります。 +証明書の再署名に使用された公開鍵と秘密鍵のペアは、サブジェクト公開鍵情報で参照されているオリジナルの公開鍵と明らかに一致しなくなりました。 +どうして `#verify` は ` true` を返すのでしょうか? + +### 鍵の検証方法 + +`X509Certificate#verify` は OpenSSL の[`X509_verify`](https://github.com/openssl/openssl/blob/master/crypto/x509/x_all.c#L74) 関数を利用しています(内部的には [`ASN1_item_verify`](https://github.com/openssl/openssl/blob/master/crypto/asn1/a_verify.c#L134) 関数を呼び出しています)。 +これらの関数は、提示された公開鍵を指定して署名の有効性を確立します。 +ところが、指定された鍵が証明書で参照されているサブジェクト公開鍵と実際に一致するかどうかは**検証されません**。 +これは、このシナリオでは「`X509Certificate#verify` の期待する振る舞いは `true` を返すこと」を意味します。 +このチェックを省略しても、総体的に X.509 信頼モデルのセキュリティに大きな影響はありません。 + +RFC 5280 の 4.1.1.3 項は、CA が証明書に含まれる情報の正確さを「証明書の署名を計算すること」で確認すると明記しています。 +上記のサンプルコードはこの原則に違反していますが、セキュリティを脅かすものではありません。 + +## 潜在的なリスク + +2 通り考えられます: + +### ルート証明書の再署名 + +ユーザーとして、私たちは無条件にルート証明書を信頼します。 +有効なな情報が含まれていない場合でも、公的に認められたルート証明書であるというステータスだけで、それらを元の状態に保つことができます。 +たとえば、OpenSSL 自体は同様の理由からデフォルトで自己署名ルート証明書の署名をチェックしません。 + +参考: [X509_V_FLAG_CHECK_SS_SIGNATURE documentation](https://www.openssl.org/docs/crypto/X509_VERIFY_PARAM_set_flags.html) + +再署名されたルート証明書は事実上の「自己署名」証明書になります(ただし、サブジェクト公開鍵情報は正しくありません)。 +これは正常な自己署名ルート証明書より危険ではありません。 +事実、署名がなければ、有効なルート証明書と完全に一致する可能性のある自己署名ルート証明書は誰でも作成できます。 +私たちは所有するだけでルート証明書を信頼するため、クライアントの「このルート証明書は信頼する」という積極的な同意がない限り、詐欺まがいな証明書に意味はありません。 + +### 中間証明書またはリーフ証明書の再署名 + +非ルート証明書の再署名もまた X.509 信頼モデルのセキュリティを脅かすものではありません。 +通常はこのような種類の証明書をあらかじめ所有していない限り、[パス検証手続き](http://tools.ietf.org/html/rfc5280#section-6)中にこのような偽装は検出されます。 +ここで、非ルート証明書の署名は、発行する証明書の公開鍵を使用して検証されます。 +証明書チェーンのある時点で、偽造は最終的に無効な証明書署名値という形で検出されます。 + +## まとめ + +結論として、`X509Certificate#verify` は期待どおりに動作すると考えています。 +私たち以外の誰かも自力で[同じ結論](https://github.com/adrienthebo/cve-2014-2734/)に行き着いたため、CVE-2014-2734 に異議を唱え、その取り消しを求めました。 +[オリジナルのコンセプトの実証](https://gist.github.com/emboss/91696b56cd227c8a0c13)は、コメントを含め、完全な分析結果として閲覧することができます。 From 45ecaadb25d8ea1460c51471750c22f227ea99f5 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Mon, 29 Nov 2021 00:05:49 +0900 Subject: [PATCH 0039/1025] Translate "OpenSSL Severe Vulnerability in TLS Heartbeat Extension (CVE-2014-0160)" (ja) Translate [https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2014-04-10-severe-openssl-vulnerability.md](https://github.com/ruby/www.ruby-lang.org/blob/master/en/news/_posts/2014-04-10-severe-openssl-vulnerability.md) to ja. --- ...2014-04-10-severe-openssl-vulnerability.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ja/news/_posts/2014-04-10-severe-openssl-vulnerability.md diff --git a/ja/news/_posts/2014-04-10-severe-openssl-vulnerability.md b/ja/news/_posts/2014-04-10-severe-openssl-vulnerability.md new file mode 100644 index 0000000000..98c992bfe7 --- /dev/null +++ b/ja/news/_posts/2014-04-10-severe-openssl-vulnerability.md @@ -0,0 +1,59 @@ +--- +layout: news_post +title: "OpenSSL の TLS ハートビート拡張による重大な脆弱性について(CVE-2014-0160)" +author: "hone and zzak" +translator: "jinroq" +date: 2014-04-10 01:04:27 +0000 +tags: security +lang: ja +--- + +OpenSSL の TLS/DTLS(トランスポート層セキュアプロトコル)ハートビート拡張(`RFC6520`)の実装で重大な脆弱性が発見されました。 +この脆弱性は [CVE-2014-0160](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-0160) として登録されています。 + +サーバーからクライアントへ、およびクライアントからサーバーへのメモリの内容を利己的に開示される可能性があります。 +攻撃者は、SSL 暗号化に使用される秘密鍵や認証トークンなどを含む機密データをメモリから遠隔操作によって取得できます。 + +詳細は [heartbleed.com](http://heartbleed.com) を参照してください. + +## Ruby の影響範囲 + +Ruby は、標準添付ライブラリ OpenSSL の C 拡張機能を介した脆弱な OpenSSL のバージョンに対して静的コンパイルをされると影響を受けます。 + +バージョン 1.0.1 以上 1.0.1f 以下の OpenSSL がこの攻撃に対して脆弱です。 +Ruby にリンクしている OpenSSL ライブラリのバージョンを検証するには、以下を実行してください。 + +{% highlight sh %} +ruby -v -ropenssl -rfiddle -e 'puts Fiddle::Function.new(Fiddle.dlopen(nil)["SSLeay_version"], [Fiddle::TYPE_INT], Fiddle::TYPE_VOIDP).call(0)' +{% endhighlight %} + +Ruby を使って現在インストールされている OpenSSL のバージョンを確認するには、以下を実行してください。 + +{% highlight sh %} +ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION' +{% endhighlight %} + +[emboss のスクリプト](https://github.com/emboss/heartbeat)を使ってクライアントソフトウェア、または実行中のサービスが脆弱かどうかを確認できます。 + +## 解決策 + +最新版である OpenSSL バージョン `1.0.1g` もしくはそれ以降にアップグレードする必要があります。そのためには最新の OpenSSL が提供されているかを現在使っている OS パッケージ管理システムで確認する必要があります。 +利用可能なバージョン番号に関係なく、その OpenSSL のバージョンにパッチが適用されているかを確認するために、OS ディストリビューターに相談する必要があるかもしれません。 + +アップグレードがオプションではない場合、ビルド時に `-DOPENSSL_NO_HEARTBEATS` オプションを付け、パッチが適用されている OpenSSL を再コンパイルします。 + +アプグレードされている OpenSSL を使っているなら、脆弱なバージョンの OpenSSL へのリンクがないことを確認している Ruby を再コンパイルすることを推奨します。 + +これは、RVM や ruby-build のような Ruby をビルドするために使うツールを更新することを意味します。 +Ruby を自分でビルドする場合は、コンパイル時にアップグレードされた OpenSSL をインストールしているディレクトリにリンクするよう `--with-openssl-dir` オプションを使用してください。。 + +{% highlight sh %} +$ ./configure --with-openssl-dir=/path/to/openssl +$ make +$ make install +{% endhighlight %} + +OpenSSL と Ruby をアップグレードした後、脆弱なバージョンを使っている全てのプログラムを再起動することが重要です。 + +多くの OS ディストリビューションは、この攻撃に脆弱であるライブラリに対し、パッチを適用したバージョンと再構築されたパッケージをすでに提供しています(もしくは間もなく提供する予定です)。 +安全性を確保するために、OS ディストリビューターを監視することが重要です。 From 1951efd3308b9371d282d0c300e855a61fbe2177 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 4 Dec 2021 07:46:18 +0900 Subject: [PATCH 0040/1025] Revised in the review. --- ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md index 6d2f0d0343..ca45ac42cd 100644 --- a/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md +++ b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -12,7 +12,7 @@ Net::IMAP 内の StartTLS ストリッピングに脆弱性が発見されまし この脆弱性は [CVE-2021-32066](https://nvd.nist.gov/vuln/detail/CVE-2021-32066) として登録されています。 Ruby をアップグレードすることを強く推奨します。 -net-imap は Ruby 3.0.1 の デフォルト gem ですが、パッケージ化の問題があるため、Ruby 自体をアップグレードしてください。 +net-imap は Ruby 3.0.1 の デフォルト gem ですが、パッケージ化に問題があるため、Ruby 自体をアップグレードしてください。 ## 詳細 From 39180f8bf65f45aa3bdd132bdbeed34f7a14a73d Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 4 Dec 2021 08:08:16 +0900 Subject: [PATCH 0041/1025] Revised in the review. --- ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md index ca45ac42cd..0a54c65239 100644 --- a/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md +++ b/ja/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -16,7 +16,7 @@ net-imap は Ruby 3.0.1 の デフォルト gem ですが、パッケージ化 ## 詳細 -Net::IMAP は、StartTLS が不明な応答で失敗した場合に例外を発生させません。これにより、中間者攻撃者がクライアントとレジストリ間のネットワークの場所を利用して StartTLS コマンドをブロックできる可能性があります。つまり、中間者攻撃者が TLS 保護をバイパスできる可能性があります。 +Net::IMAP は、StartTLS が不明な応答で失敗した場合に例外を発生させません。これにより、中間者攻撃者がクライアントとレジストリ間のネットワーク位置を利用して StartTLS コマンドをブロックし、結果として、中間者攻撃者が TLS 保護をバイパスできる可能性があります。 これは「StartTLS ストリッピング攻撃」とも呼ばれています。 ## 影響を受けるバージョン From c9dea54abfe645b9203e4b20003e082a95015e8b Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Sat, 4 Dec 2021 21:36:05 +0900 Subject: [PATCH 0042/1025] Polished sentences. --- ...-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md index 65589d9ebe..db1112833a 100644 --- a/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md +++ b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -1,6 +1,6 @@ --- layout: news_post -title: "CVE-2021-28965: REXML 内の XML ラウンドトリップの脆弱性について" +title: "CVE-2021-28965: REXML 内の XML ラウンドトリップ脆弱性について" author: "mame" translator: "jinroq" date: 2021-04-05 12:00:00 +0000 @@ -8,13 +8,13 @@ tags: security lang: ja --- -Ruby にバンドルされている REXML gem 内の XML ラウンドトリップに脆弱性が発見されました。 +Ruby にバンドルされている REXML gem 内の XML ラウンドトリップ脆弱性が発見されました。 この脆弱性は [CVE-2021-28965](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28965) として登録されています。 REXML gem をアップグレードすることを強く推奨します。 ## 詳細 -加工された XML ドキュメントをパーシングおよびシリアル化する場合、REXML gem(Ruby にバンドルされているものを含む)は、元のドキュメントとは構造が異なる誤った XML ドキュメントを生成する可能性があります。 +特定の加工が施された XML ドキュメントをパーシングおよびシリアル化する場合、REXML gem(Ruby にバンドルされているものを含む)は、元のドキュメントとは構造が異なる誤った XML ドキュメントを生成する可能性があります。 この問題の影響はコンテキストによって大きく異なりますが、REXML を使用している一部のプログラムでは脆弱性が生じる可能性があります。 REXML gem をバージョン 3.2.5 以降に更新してください。 From 178e4af80f26aabe7cc3edf365dc395994338616 Mon Sep 17 00:00:00 2001 From: jinroq <2787780+jinroq@users.noreply.github.com> Date: Mon, 6 Dec 2021 12:07:14 +0900 Subject: [PATCH 0043/1025] Revised points made in reviews. Revised the points made in [this comment](https://github.com/ruby/www.ruby-lang.org/pull/2747). --- ...4-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md index db1112833a..a30f112f91 100644 --- a/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md +++ b/ja/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -8,7 +8,7 @@ tags: security lang: ja --- -Ruby にバンドルされている REXML gem 内の XML ラウンドトリップ脆弱性が発見されました。 +Ruby にバンドルされている REXML gem に XML ラウンドトリップ脆弱性が発見されました。 この脆弱性は [CVE-2021-28965](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28965) として登録されています。 REXML gem をアップグレードすることを強く推奨します。 From 93192c190415158183f702a6fcad0838dc975568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Mon, 6 Dec 2021 14:35:10 -0500 Subject: [PATCH 0044/1025] Translation of CVE-2021-41817 to spanish (#2758) * Translation of CVE-2021-41817 to spanish * No blank line at end * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa * Update es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md Co-authored-by: Gustavo Villa Co-authored-by: Gustavo Villa --- ...p-vulnerability-in-rexml-cve-2021-28965.md | 2 +- ...arsing-method-regexp-dos-cve-2021-41817.md | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md diff --git a/es/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md b/es/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md index fcc342219d..325205277b 100644 --- a/es/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md +++ b/es/news/_posts/2021-04-05-xml-round-trip-vulnerability-in-rexml-cve-2021-28965.md @@ -41,7 +41,7 @@ posterior tan pronto como sea posible. ## Versiones afectadas -* Ruby 2.5.8 o anterior (NO podrá usar `gem upgrade rexml` +* Ruby 2.5.8 o anterior (NO podrá usar `gem update rexml` con estas versiones.) * Ruby 2.6.6 o anterior * Ruby 2.7.2 o anterior diff --git a/es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md b/es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md new file mode 100644 index 0000000000..8f1bacc61e --- /dev/null +++ b/es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md @@ -0,0 +1,57 @@ +--- +layout: news_post +title: "CVE-2021-41817: Vulnerabilidad de denegación de servicio por Expresiones Reguales en los métodos para reconocer fechas" +author: "mame" +translator: vtamara +date: 2021-11-15 08:00:00 +0000 +tags: security +lang: es +--- + +Hemos publicado la gema `date` con versiones 3.2.1, 3.1.2, 3.0.2 y 2.0.1 +que incluyen una corrección de seguridad a una vulnerabilidad de denegación +de servicio por expresiones regulares (ReDoS) en los métodos para reconocer +fechas. +Un atacante podría explotar esta vulnerabilidad para generar +un ataque de denegación de servicio efectivo. + +A esta vulnerabilidad se le ha asignado el identificador CVE +[CVE-2021-41817](https://nvd.nist.gov/vuln/detail/CVE-2021-41817). + +## Detalles + +Los métodos para reconocer fechas incluyendo `Date.parse` usan +expresiones regulares internamente, algunas de las cuales son vulnerables +a denegación de servicio por expresiones regulares. +Las aplicaciones y librerías que emplean tales métodos con entradas +no confiables pueden verse afectadas. + +La corrección limita el tamaño de la entrada a 128 bytes de manera +predeterminada en lugar de cambiar las expresiones regulares. +Esto es porque la gema Date usa muchas expresiones regulares y es posible que aún haya +vulnerabilidades no descubiertas en algunas. Por compatibilidad, se +permite eliminar la limitación pasando explícitamente la palabra +reservada `limit` en `nil`, como en `Date.parse(str, limit: nil)`, +pero tenga en cuenta que el reconocimiento puede tardar un largo tiempo. + +Por favor actualice la gema date a una de las versiones 3.2.1, 3.1.2, 3.0.2, +2.0.1 o posterior. Puede usar `gem update date` para actualizarla. +Si usa bundler, por favor añada `gem "date", ">= 3.2.1"` a su `Gemfile`. +De forma alternativa, puede actualizar Ruby a 3.0.3, 2.7.5, 2.6.9 o posterior. + +## Versiones afectadas + +* gema date 2.0.0 y anteriores (distribuidas con la serie Ruby 2.6 antes de Ruby 2.6.9) +* gema date 3.0.1 y anteriores (distribuidas con la serie Ruby 2.7 antes de Ruby 2.7.5) +* gema date 3.1.1 y anteriores (distribuida con la serie Ruby 3.0 antes de Ruby 3.0.3) +* gema date gem 3.2.0 y anteriores + +## Créditos + +Agradecemos a [svalkanov](https://github.com/SValkanov/) por descubrir +el problema. + +## Historia + +* Publicado originalmente en inglés el 2021-11-15 08:00:00 (UTC) +* Mención sobre nuevas versiones de Ruby el 2021-11-24 13:20:00 (UTC) From 75c9ef329eb90cd5411df8e7fa9f3da49a32f1de Mon Sep 17 00:00:00 2001 From: Andrias Meisyal Date: Sat, 4 Dec 2021 20:23:33 +0700 Subject: [PATCH 0045/1025] Translate CVE-2021-32066: A StartTLS stripping vulnerability in Net::IMAP (id) --- ...21-07-07-starttls-stripping-in-net-imap.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 id/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md diff --git a/id/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md b/id/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md new file mode 100644 index 0000000000..0e83033da3 --- /dev/null +++ b/id/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md @@ -0,0 +1,40 @@ +--- +layout: news_post +title: "CVE-2021-32066: Kerentanan StartTLS stripping pada Net::IMAP" +author: "shugo" +translator: "meisyal" +date: 2021-07-07 09:00:00 +0000 +tags: security +lang: id +--- + +Sebuah kerentanan StartTLS *stripping* telah ditemukan pada Net::IMAP. +Kerentanan ini telah ditetapkan dengan penanda CVE +[CVE-2021-32066](https://nvd.nist.gov/vuln/detail/CVE-2021-32066). +Kami sangat merekomendasikan untuk memperbarui Ruby. + +net-imap adalah sebuah *default gem* pada Ruby 3.0.1, tetapi *gem* tersebut +memiliki masalah pengemasan. Sehingga, mohon perbarui Ruby. + +## Detail + +Net::IMAP tidak akan mengeluarkan sebuah *exception* jika StartTLS gagal +dengan sebuah respons yang tidak dikenal, yang mana mungkin memperbolehkan +penyerang *man-in-the-middle* untuk melewati perlindungan TLS dengan +memanfaatkan posisi jaringan antara *client* dan *registry* untuk mengeblok +perintah StartTLS, alias "StartTLS stripping attack." + +## Versi Terimbas + +* Rangkaian Ruby 2.6: 2.6.7 dan sebelumnya +* Rangkaian Ruby 2.7: 2.7.3 dan sebelumnya +* Rangkaian Ruby 3.0: 3.0.1 dan sebelumnya + +## Rujukan + +Terima kasih kepada [Alexandr Savca](https://hackerone.com/chinarulezzz) yang +telah melaporkan kerentanan ini. + +## Riwayat + +* Semula dipublikasikan pada 2021-07-07 09:00:00 UTC From 6a7c5e36a74e64d4b689bb89908be5fa68f1a19a Mon Sep 17 00:00:00 2001 From: billaul Date: Sun, 19 Dec 2021 17:22:33 +0100 Subject: [PATCH 0046/1025] Update index.md --- fr/community/index.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fr/community/index.md b/fr/community/index.md index 97898265cd..984296a32d 100644 --- a/fr/community/index.md +++ b/fr/community/index.md @@ -25,6 +25,12 @@ Quelques liens à visiter: disponibles. Si vous avez des questions sur Ruby, les poser sur une de ces listes est un moyen efficace pour obtenir rapidement des réponses. +[Server Discord Ruby (lien d'invitation)][ruby-discord] +: Le serveur Discord Ruby est un endroit où vous pouvez discuter avec + d'autres rubyistes, obtenir de l'aide pour vos questions sur Ruby ou + aider les autres. Discord est un bon point d'entrée pour les nouveaux + développeurs et il est facile à rejoindre. + [IRC (#ruby)](https://web.libera.chat/#ruby) : Le canal IRC anglophone #ruby est un endroit fantastique pour discuter en temps réel avec d’autres rubyistes. @@ -53,5 +59,6 @@ Informations générales [ruby-central]: http://rubycentral.org/ +[ruby-discord]: https://ruby-discord.com/ [ruby-opendir]: https://dmoztools.net/Computers/Programming/Languages/Ruby/ [rails-opendir]: https://dmoztools.net/Computers/Programming/Languages/Ruby/Software/Frameworks/Rails/ From 840bad163a6756708734b5d7626e037c83fc95ff Mon Sep 17 00:00:00 2001 From: Andrias Meisyal Date: Sat, 18 Dec 2021 20:23:19 +0700 Subject: [PATCH 0047/1025] Translate Ruby 2.6.8 released news (id) --- .../_posts/2021-07-07-ruby-2-6-8-released.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 id/news/_posts/2021-07-07-ruby-2-6-8-released.md diff --git a/id/news/_posts/2021-07-07-ruby-2-6-8-released.md b/id/news/_posts/2021-07-07-ruby-2-6-8-released.md new file mode 100644 index 0000000000..0b922bfdcc --- /dev/null +++ b/id/news/_posts/2021-07-07-ruby-2-6-8-released.md @@ -0,0 +1,64 @@ +--- +layout: news_post +title: "Ruby 2.6.8 Dirilis" +author: "usa" +translator: "meisyal" +date: 2021-07-07 09:00:00 +0000 +lang: id +--- + +Ruby 2.6.8 telah dirilis. + +Rilis ini memuat perbaikan keamanan. +Mohon cek topik-topik di bawah ini untuk lebih detail. + +* [CVE-2021-31810: Kerentanan respons FTP PASV yang dipercaya pada Net::FTP]({%link id/news/_posts/2021-07-07-trusting-pasv-responses-in-net-ftp.md %}) +* [CVE-2021-32066: Kerentanan StartTLS stripping pada Net::IMAP]({%link id/news/_posts/2021-07-07-starttls-stripping-in-net-imap.md %}) +* [CVE-2021-31799: Sebuah kerentanan command injection pada RDoc]({%link id/news/_posts/2021-05-02-os-command-injection-in-rdoc.md %}) + +Kami biasanya tidak memperbaiki Ruby 2.6, kecuali perbaikan keamanan. Tetapi, +rilis ini memuat beberapa perbaikan *regressed bug* dan *build problem*. +Lihat [commit logs](https://github.com/ruby/ruby/compare/v2_6_7...v2_6_8) +untuk detail. + +Ruby 2.6 saat ini berada pada fase perawatan keamanan hingga akhir Maret 2022. +Setelah bulan tersebut, perawatan Ruby 2.6 akan berakhir. +Kami merekomendasikan Anda untuk mulai merencanakan migrasi ke Ruby versi +terbaru, seperti 3.0 atau 2.7. + +## Unduh + +{% assign release = site.data.releases | where: "version", "2.6.8" | first %} + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Komentar Rilis + +Banyak *committer*, pengembang, dan pengguna yang telah menyediakan laporan +*bug* membantu kami untuk membuat rilis ini. Terima kasih atas kontribusinya. From f1e7ad610a7aa5a5e48b4894a6c8b9b205b5afbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Wed, 22 Dec 2021 15:57:40 -0500 Subject: [PATCH 0048/1025] Translation of CVE 2021 41816 to spanish (#2760) * Translation of CVE 2021 41816 to spanish * lang es --- ...errun-in-cgi-escape_html-cve-2021-41816.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md diff --git a/es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md b/es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md new file mode 100644 index 0000000000..6a64284388 --- /dev/null +++ b/es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md @@ -0,0 +1,46 @@ +--- +layout: news_post +title: "CVE-2021-41816: Desbordamiento de búfer en CGI.escape_html" +author: "mame" +translator: vtamara +date: 2021-11-24 12:00:00 +0000 +tags: security +lang: es +--- + +Una vulnerabilidad de desbordamiento de búfer fue descubierta en +CGI.escape_html. +A esta vulnerabilidad se le ha asignado el identificador CVE +[CVE-2021-41816](https://nvd.nist.gov/vuln/detail/CVE-2021-41816). +Recomendamos enfáticamente actualizar Ruby. + +## Detalles + +Una vulnerabilidad de seguridad que causa desbordamientos de búfer cuando +el usuario pasa una cadenas muy grande (> 700MB) a `CGI.escape_html` en +una plataforma donde el tipo `long` emplee 4 bytes, tipicamente, Windows. + +Por favor actualice la gema cgi a la versión 0.3.1, 0.2,1, y 0.1,1 o posterior. +Puede usar `gem update cgi` para actualizarla. Si está usando bundler, +por favor añada `gem "cgi", ">= 0.3.1"` a su archivo `Gemfile`. +Alternativamente, por favor actualice Ruby a 2.7.5 o a 3.0.3. + +Este problema fue introducido desde Ruby 2.7, así que las versiones de cgi +incorporadas en Ruby 2.6 no es vulnerable. + +## Versiones afectadas + +* Gema cgi 0.1.0 o anterior (que se distribuyó con la serie Ruby 2.7 antes de + Ruby 2.7.5) +* Gema cgi 0.2.0 o anterior (que se distribuyó con la serie Ruby 3.0 antes de + Ruby 3.0.3) +* Gema cgi 0.3.0 o anterior + +## Créditos + +Agradecimientos a [chamal](https://hackerone.com/chamal) por descubrir este +problema. + +## Historia + +* Publicado originalmente el 2021-11-24 12:00:00 (UTC) From b923ddb8c6558223d1f691749d21985022132c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Thu, 23 Dec 2021 09:38:46 -0500 Subject: [PATCH 0049/1025] Translation of CVE 2021-41819 to spanish (#2763) --- ...fing-in-cgi-cookie-parse-cve-2021-41819.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md diff --git a/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md b/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md new file mode 100644 index 0000000000..2648f13314 --- /dev/null +++ b/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md @@ -0,0 +1,59 @@ +--- +layout: news_post +title: "CVE-2021-41819: Cookie Prefix Spoofing in CGI::Cookie.parse" +author: "mame" +translator: vtamara +date: 2021-11-24 12:00:00 +0000 +tags: security +lang: es +--- + +Se descubrió una vulnerabilidad de suplantación de identidad de prefijos de +galletas (cookies) en CGI::Cookie.parse. +A esta vulnerabilidad se el ha asignado el identificador +CVE [CVE-2021-41819](https://nvd.nist.gov/vuln/detail/CVE-2021-41819). +Recomendamos con énfasis actualizar Ruby. + +## Detalles + +La antigua versión de `CGI::Cookie.parse` aplicaba decodificación de URL a los +nombres de galletas. +Un atacante podría explotar esta vulnerabilidad para suplantar prefijos de +seguridad en los nombres de las galletas, que podría permitirle engañar +a una aplicación vulnerable. + +Con este arreglo, `CGI::Cookie.parse` ya no decodifica los nombres +de las galletas. +Note que esto es una incompatibilidad si los nombres de galletas que +está usando incluyendo carácteres no alfanuméricos que no están +codificados como URL. + +Este es el mismo incidente [CVE-2020-8184](https://nvd.nist.gov/vuln/detail/CVE-2020-8184). + +Si está usando Ruby 2.7 o 3.0: + +* Por favor actualice la gema cgi a la versión 0.3.1, 0.2,1, y 0.1,1 + o posterior. Puede usar `gem update cgi` para actualizarla. Si usa + bundler por favor agregue `gem "cgi", ">= 0.3.1"` a su `Gemfile`. +* De manera alternativa, por favor actualice Ruby a 2.7.5 o 3.0.3. + +Si usa Ruby 2.6: + +* Por favor actualice Ruby a 2.6.9. *No puede usar `gem update cgi` con Ruby 2.6 + o anteriores.* + +## Versiones afectadas + +* ruby 2.6.8 o anteriores (*No* puede usar `gem update cgi` para esta versión.) +* Gema cgi 0.1.0 o anteriores (que son versiones incorporadas en la serie Ruby 2.7 antes de Ruby 2.7.5) +* Gema cgi 0.2.0 o anteriores (que son versiones incorporadas en la serie Ruby 3.0 antes de Ruby 3.0.3) +* Gema cgi 0.3.0 o anteriores + +## Créditos + +Agradecemos a [ooooooo_q](https://hackerone.com/ooooooo_q) por descubrir +este problema. + +## Historia + +* Publicado originalmente el 2021-11-24 12:00:00 (UTC) From 0df598db6ec35d2f8c9070e448110a354a78952a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Thu, 23 Dec 2021 11:53:56 -0500 Subject: [PATCH 0050/1025] Translation of release of Ruby 2.6.9, 2.7.5 and 3.0.3 to spanish (#2764) --- ...fing-in-cgi-cookie-parse-cve-2021-41819.md | 2 +- .../_posts/2021-11-24-ruby-2-6-9-released.md | 63 +++++++++++++++++++ .../_posts/2021-11-24-ruby-2-7-5-released.md | 63 +++++++++++++++++++ .../_posts/2021-11-24-ruby-3-0-3-released.md | 60 ++++++++++++++++++ 4 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 es/news/_posts/2021-11-24-ruby-2-6-9-released.md create mode 100644 es/news/_posts/2021-11-24-ruby-2-7-5-released.md create mode 100644 es/news/_posts/2021-11-24-ruby-3-0-3-released.md diff --git a/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md b/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md index 2648f13314..664dbe5b00 100644 --- a/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md +++ b/es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md @@ -1,6 +1,6 @@ --- layout: news_post -title: "CVE-2021-41819: Cookie Prefix Spoofing in CGI::Cookie.parse" +title: "CVE-2021-41819: Suplantación de identidad del prefijo de galletas en CGI::Cookie.parse" author: "mame" translator: vtamara date: 2021-11-24 12:00:00 +0000 diff --git a/es/news/_posts/2021-11-24-ruby-2-6-9-released.md b/es/news/_posts/2021-11-24-ruby-2-6-9-released.md new file mode 100644 index 0000000000..62f48cbae2 --- /dev/null +++ b/es/news/_posts/2021-11-24-ruby-2-6-9-released.md @@ -0,0 +1,63 @@ +--- +layout: news_post +title: "Publicado Ruby 2.6.9" +author: "usa" +translator: vtamara +date: 2021-11-24 12:00:00 +0000 +lang: es +--- + +Ruby 2.6.9 ha sido publicado. +CVE-2021-41819: Suplantación de identidad del prefijo de galletas en CGI::Cookie.parse +Esta versión incluye correcciones de seguridad. +Por favor revise los temas siguientes para ver detalles. +Please check the topics below for details. + +* [CVE-2021-41817: Vulnerabilidad de denegación de servicio por Expresiones Reguales en los métodos para reconocer fechas]({%link es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md %}) +* [CVE-2021-41819: Suplantación de identidad del prefijo de galletas en CGI::Cookie.parse]({%link es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md %}) + +Ver detalles en la [bitácora de cambios](https://github.com/ruby/ruby/compare/v2_6_8...v2_6_9). + +Ruby 2.6 ahora está en la fase de mantenimiento de seguridad, hasta el final +de Marzo de 2022. +Tras esa fecha, cesará el mantenimiento a Ruby 2.6. +Le recomendamos empezar a planear la migración a una versińo más +reciente de ruby, tal como 3.0 o 2.7. + +## Descargas + +{% assign release = site.data.releases | where: "version", "2.6.9" | first %} + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Comentario de la versión + +Muchos contribuidores, desarrolladores y usuarios proveyeron reportes +de fallas que ayudaron a completar esta versión. +Gracias por sus contribuciones. diff --git a/es/news/_posts/2021-11-24-ruby-2-7-5-released.md b/es/news/_posts/2021-11-24-ruby-2-7-5-released.md new file mode 100644 index 0000000000..641d91f64f --- /dev/null +++ b/es/news/_posts/2021-11-24-ruby-2-7-5-released.md @@ -0,0 +1,63 @@ +--- +layout: news_post +title: "Publicado Ruby 2.7.5" +author: "usa" +translator: vtamara +date: 2021-11-24 12:00:00 +0000 +lang: es +--- + +Ruby 2.7.5 ha sido publicado. + +Esta versión incluye correcciones de seguridad. +Por favor revise los temas siguientes para ver detalles. + +* [CVE-2021-41817: Vulnerabilidad de denegación de servicio por Expresiones Reguales en los métodos para reconocer fechas]({%link es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md %}) +* [CVE-2021-41819: Suplantación de identidad del prefijo de galletas en CGI::Cookie.parse]({%link es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md %}) +* [CVE-2021-41816: Desbordamiento de búfer en CGI.escape_html]({%link es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md %}) + +Ver detalles en la +[bitácora de cambios](https://github.com/ruby/ruby/compare/v2_7_4...v2_7_5). + + +## Descargas + +{% assign release = site.data.releases | where: "version", "2.7.5" | first %} + + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Comentario de la versión + +Muchos contribuidores, desarrolladores y usuarios proveyeron reportes +de fallas que nos ayudaron a completar esta versión. +Gracias por sus contribuciones. + +El mantenimiento de Ruby 2.7, incluida esta versión, se basa en el "Acuerdo +para una versión estable de Ruby" de la Asociación Ruby. diff --git a/es/news/_posts/2021-11-24-ruby-3-0-3-released.md b/es/news/_posts/2021-11-24-ruby-3-0-3-released.md new file mode 100644 index 0000000000..1836129518 --- /dev/null +++ b/es/news/_posts/2021-11-24-ruby-3-0-3-released.md @@ -0,0 +1,60 @@ +--- +layout: news_post +title: "Publicación de Ruby 3.0.3" +author: "nagachika" +translator: vtamara +date: 2021-11-24 12:00:00 +0000 +lang: es +--- + +Ruby 3.0.3 ha sido publicado. + +Esta versión incluye correcciones de seguridad. +Por favor revise los temas siguientes para ver detalles. + +* [CVE-2021-41817: Vulnerabilidad de denegación de servicio por Expresiones Reguales en los métodos para reconocer fechas]({%link es/news/_posts/2021-11-15-date-parsing-method-regexp-dos-cve-2021-41817.md %}) +* [CVE-2021-41816: Desbordamiento de búfer en CGI.escape_html]({%link es/news/_posts/2021-11-24-buffer-overrun-in-cgi-escape_html-cve-2021-41816.md %}) +* [CVE-2021-41819: Suplantación de identidad del prefijo de galletas en CGI::Cookie.parse]({%link es/news/_posts/2021-11-24-cookie-prefix-spoofing-in-cgi-cookie-parse-cve-2021-41819.md %}) + +Ver detalles en la +[bitácora de cambios](https://github.com/ruby/ruby/compare/v2_7_4...v2_7_5). + + +## Descargas + +{% assign release = site.data.releases | where: "version", "3.0.3" | first %} + + +* <{{ release.url.bz2 }}> + + SIZE: {{ release.size.bz2 }} + SHA1: {{ release.sha1.bz2 }} + SHA256: {{ release.sha256.bz2 }} + SHA512: {{ release.sha512.bz2 }} + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Comentario de la versión + +Muchos contribuidores, desarrolladores y usuarios proveyeron reportes +de fallas que nos ayudaron a completar esta versión. +Gracias por sus contribuciones. From af3e0d344a11738ea684d0c2cf5e662f9f934228 Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Sat, 25 Dec 2021 19:59:44 +0900 Subject: [PATCH 0051/1025] Ruby 3.1.0 Released (#2765) --- _data/branches.yml | 4 +- _data/downloads.yml | 2 +- _data/releases.yml | 24 ++ .../_posts/2021-12-25-ruby-3-1-0-released.md | 259 ++++++++++++++++++ .../_posts/2021-12-25-ruby-3-1-0-released.md | 256 +++++++++++++++++ 5 files changed, 542 insertions(+), 3 deletions(-) create mode 100644 en/news/_posts/2021-12-25-ruby-3-1-0-released.md create mode 100644 ja/news/_posts/2021-12-25-ruby-3-1-0-released.md diff --git a/_data/branches.yml b/_data/branches.yml index ebd2220b93..a4054fb534 100644 --- a/_data/branches.yml +++ b/_data/branches.yml @@ -9,8 +9,8 @@ # eol_date: date of EOL (YYYY-MM-DD) - name: 3.1 - status: preview - date: + status: normal maintenance + date: 2021-12-25 eol_date: - name: 3.0 diff --git a/_data/downloads.yml b/_data/downloads.yml index 54a2601a06..10644898d1 100644 --- a/_data/downloads.yml +++ b/_data/downloads.yml @@ -4,10 +4,10 @@ # optional preview: - - 3.1.0-preview1 stable: + - 3.1.0 - 3.0.3 - 2.7.5 diff --git a/_data/releases.yml b/_data/releases.yml index 82ff598065..a7a6341109 100644 --- a/_data/releases.yml +++ b/_data/releases.yml @@ -21,6 +21,30 @@ # 3.1 series +- version: 3.1.0 + date: 2021-12-25 + post: /en/news/2021/12/25/ruby-3-1-0-released/ + url: + gz: https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz + zip: https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.zip + xz: https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.xz + size: + gz: 19204319 + zip: 23207824 + xz: 14051880 + sha1: + gz: 3945f8043286975cfc016d288abcb334574796d9 + zip: 88963d8244bb122668c1fc8dfa3a8a5289c87146 + xz: 3d5a9cae293763787185ccc04f05aecfb6790703 + sha256: + gz: 8dc75f2f7b5552a3a10abc22ffbf1bf85909326d715647dcdf5ce878c349a81d + zip: 8a051fdd5ba43bd072c3179bbc65c581974c06142b97aa049fe04ec6d5fc8447 + xz: 8594c076e1b06a896143d3a70163ddc12d81ca55c906ee5ee215587c2df52382 + sha512: + gz: ede15d99afb3087412a45038ad9266af67edc953fae08356a64235706766d171715bc927b045e1b07d0736cdf83f1891944b6861dad39f4519482135493cc93c + zip: f52ea893e158d79074ab7f551778df2189c184bc7b931e27ad0e7600ceab743d88d8b07ba3ff400b65c7866aa62734b72efe89216d5c4106391b40476f0d30ac + xz: 0ef0c19b6ae5af9878d8783a7b072e7f86c6d0e747866365564891c94452f334c901419bba80b6361c803c031ffa6b98d237eb4c6e017f8e6fe652cc336572de + - version: 3.1.0-preview1 date: 2021-11-09 post: /en/news/2021/11/09/ruby-3-1-0-preview1-released/ diff --git a/en/news/_posts/2021-12-25-ruby-3-1-0-released.md b/en/news/_posts/2021-12-25-ruby-3-1-0-released.md new file mode 100644 index 0000000000..caf363cc42 --- /dev/null +++ b/en/news/_posts/2021-12-25-ruby-3-1-0-released.md @@ -0,0 +1,259 @@ +--- +layout: news_post +title: "Ruby 3.1.0 Released" +author: "naruse" +translator: +date: 2021-12-25 00:00:00 +0000 +lang: en +--- + +{% assign release = site.data.releases | where: "version", "3.1.0" | first %} + +We are pleased to announce the release of Ruby {{ release.version }}. + + +## YJIT: New experimental in-process JIT compiler + + +Ruby 3.1 merges YJIT, a new in-process JIT compiler developed by Shopify. + +Since [Ruby 2.6 introduced MJIT in 2018](https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/), its performance greatly improved, and finally [we achieved Ruby3x3 last year](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/). But even though Optcarrot has shown impressive speedups, the JIT hasn't benefited real world business applications. + +Recently Shopify contributed many Ruby improvements to speed up their Rails application. YJIT is an important contribution, and aims to improve the performance of Rails applications. + +Though MJIT is a method-based JIT compiler and uses an external C compiler, YJIT uses Basic Block Versioning and includes JIT compiler inside it. With Lazy Basic Block Versioning (LBBV) it first compiles the beginning of a method, and incrementally compiles the rest when the type of arguments and variables are dynamically determined. See [YJIT: a basic block versioning JIT compiler for CRuby](https://dl.acm.org/doi/10.1145/3486606.3486781) for a detailed introduction. + +With this technology, YJIT achieves both fast warmup time and performance improvements on most real-world software, up to 22% on railsbench, 39% on liquid-render. + +YJIT is still an experimental feature, and as such, it is disabled by default. If you want to use this, specify the `--yjit` command-line option to enable YJIT. It is also limited to Unix-like x86-64 platforms for now. + +* https://bugs.ruby-lang.org/issues/18229 +* https://shopify.engineering/yjit-just-in-time-compiler-cruby +* https://www.youtube.com/watch?v=PBVLf3yfMs8 + +## debug gem: A new debugger + +A completely rewritten debugger [debug.gem](https://github.com/ruby/debug) is bundled. debug.gem has the following features: + +* Improve the debugging performance (it does not slow down the application even with the debugger) +* Support remote debugging +* Support rich debugging frontend (VSCode and Chrome browser are supported now) +* Support multi-process/multi-thread debugging +* Colorful REPL +* And other useful features like recod & replay feature, tracing feature and so on. + + + +Ruby had bundled lib/debug.rb, but it was not well maintained and it had issues about performance and features. debug.gem replaced lib/debug.rb completely. + +## error_highlight: Fine-grained error location in backtrace + +A built-in gem, error_highlight, has been introduced. It includes fine-grained error location in backtrace: + +``` +$ ruby test.rb +test.rb:1:in `
': undefined method `time' for 1:Integer (NoMethodError) + +1.time {} + ^^^^^ +Did you mean? times +``` + +Currently, only `NameError` is supported. + +This gem is enabled by default. You can disable it by using a command-line option `--disable-error_highlight`. See [the repository](https://github.com/ruby/error_highlight) in detail. + +## IRB Autocomplete and Document Display + +The IRB now has an autocomplete feature, where you can just type in the code, and the completion candidates dialog will appear. You can use Tab and Shift+Tab to move up and down. + +If documents are installed when you select a completion candidate, the documentation dialog will appear next to the completion candidates dialog, showing part of the content. You can read the full document by pressing Alt+d. + + + + +## Other Notable New Features + +### Language + +* Values in Hash literals and keyword arguments can be omitted. [Feature #14579] + * `{x:, y:}` is a syntax sugar of `{x: x, y: y}`. + * `foo(x:, y:)` is a syntax sugar of `foo(x: x, y: y)`. + +* Pin operator in pattern matching now takes an expression. [Feature #17411] + +```ruby +Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a +#=> [[3, 5], [5, 7], [11, 13]] +``` + +* Parentheses can be omitted in one-line pattern matching. [Feature #16182] + +```ruby +[0, 1] => _, x +{y: 2} => y: +x #=> 1 +y #=> 2 +``` + +### RBS + +RBS is a language to describe the structure of Ruby programs. See [the repository](https://github.com/ruby/rbs) for details. + +Updates since Ruby 3.0.0: + +* Generic type parameters can be bounded. ([PR](https://github.com/ruby/rbs/pull/844)) +* Generic type aliases are supported. ([PR](https://github.com/ruby/rbs/pull/823)) +* `rbs collection` has been introduced to manage gems' RBSs. ([doc](https://github.com/ruby/rbs/blob/master/docs/collection.md)) +* Many signatures for built-in and standard libraries have been added/updated. +* It includes many bug fixes and performance improvements too. + +See [the CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md) for more information. + +### TypeProf + +TypeProf is a static type analyzer for Ruby. It generates a prototype of RBS from non-type-annotated Ruby code. See [the document](https://github.com/ruby/typeprof/blob/master/doc/doc.md) for detail. + +The main updates since Ruby 3.0.0 is an experimental IDE support called "TypeProf for IDE". + +![Demo of TypeProf for IDE](https://cache.ruby-lang.org/pub/media/ruby310_typeprof_ide_demo.png) + +The vscode extension shows a guessed (or explicitly written in a RBS file) method signature above each method definition, draws a red underline under the code that may cause a name error or type error, and completes method names (i.e., shows method candidates). See [the document](https://github.com/ruby/typeprof/blob/master/doc/ide.md) in detail. + +Also, the release includes many bug fixes and performance improvements. + +## Performance improvements + +* MJIT + * For workloads like Rails, the default `--jit-max-cache` is changed from 100 to 10000. + The JIT compiler no longer skips compilation of methods longer than 1000 instructions. + * To support Zeitwerk of Rails, JIT-ed code is no longer cancelled + when a TracePoint for class events is enabled. + +## Other notable changes since 3.0 + +* One-line pattern matching, e.g., `ary => [x, y, z]`, is no longer experimental. +* Multiple assignment evaluation order has been changed slightly. [[Bug #4443]](https://bugs.ruby-lang.org/issues/4443) + * `foo[0], bar[0] = baz, qux` was evaluated in order `baz`, `qux`, `foo`, and then `bar` in Ruby 3.0. In Ruby 3.1, it is evaluated in order `foo`, `bar`, `baz`, and then `qux`. +* Variable Width Allocation: Strings (experimental) [[Bug #18239]](https://bugs.ruby-lang.org/issues/18239) + +* Psych 4.0 changes `Psych.load` as `safe_load` by the default. + You may need to use Psych 3.3.2 for migrating to this behavior. + [[Bug #17866]](https://bugs.ruby-lang.org/issues/17866) + +### Standard libraries updates + +* The following default gem are updated. + * RubyGems 3.3.3 + * base64 0.1.1 + * benchmark 0.2.0 + * bigdecimal 3.1.1 + * bundler 2.3.3 + * cgi 0.3.1 + * csv 3.2.2 + * date 3.2.2 + * did_you_mean 1.6.1 + * digest 3.1.0 + * drb 2.1.0 + * erb 2.2.3 + * error_highlight 0.3.0 + * etc 1.3.0 + * fcntl 1.0.1 + * fiddle 1.1.0 + * fileutils 1.6.0 + * find 0.1.1 + * io-console 0.5.9 + * io-wait 0.2.1 + * ipaddr 1.2.3 + * irb 1.4.1 + * json 2.6.1 + * logger 1.5.0 + * net-http 0.2.0 + * net-protocol 0.1.2 + * nkf 0.1.1 + * open-uri 0.2.0 + * openssl 3.0.0 + * optparse 0.2.0 + * ostruct 0.5.2 + * pathname 0.2.0 + * pp 0.3.0 + * prettyprint 0.1.1 + * psych 4.0.3 + * racc 1.6.0 + * rdoc 6.4.0 + * readline 0.0.3 + * readline-ext 0.1.4 + * reline 0.3.0 + * resolv 0.2.1 + * rinda 0.1.1 + * ruby2_keywords 0.0.5 + * securerandom 0.1.1 + * set 1.0.2 + * stringio 3.0.1 + * strscan 3.0.1 + * tempfile 0.1.2 + * time 0.2.0 + * timeout 0.2.0 + * tmpdir 0.1.2 + * un 0.2.0 + * uri 0.11.0 + * yaml 0.2.0 + * zlib 2.1.1 +* The following bundled gems are updated. + * minitest 5.15.0 + * power_assert 2.0.1 + * rake 13.0.6 + * test-unit 3.5.3 + * rexml 3.2.5 + * rbs 2.0.0 + * typeprof 0.21.1 +* The following default gems are now bundled gems. You need to add the following libraries to `Gemfile` under the bundler environment. + * net-ftp 0.1.3 + * net-imap 0.2.2 + * net-pop 0.1.1 + * net-smtp 0.3.1 + * matrix 0.4.2 + * prime 0.1.2 + * debug 1.4.0 + +See [NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md) +or [commit logs](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}) +for more details. + +With those changes, [{{ release.stats.files_changed }} files changed, {{ release.stats.insertions }} insertions(+), {{ release.stats.deletions }} deletions(-)](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}#file_bucket) +since Ruby 3.0.0! + +Merry Christmas, Happy Holidays, and enjoy programming with Ruby 3.1! + +## Download + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## What is Ruby + +Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993, +and is now developed as Open Source. It runs on multiple platforms +and is used all over the world especially for web development. diff --git a/ja/news/_posts/2021-12-25-ruby-3-1-0-released.md b/ja/news/_posts/2021-12-25-ruby-3-1-0-released.md new file mode 100644 index 0000000000..b8f5a29bfa --- /dev/null +++ b/ja/news/_posts/2021-12-25-ruby-3-1-0-released.md @@ -0,0 +1,256 @@ +--- +layout: news_post +title: "Ruby 3.1.0 リリース" +author: "naruse" +translator: +date: 2021-12-25 00:00:00 +0000 +lang: ja +--- + +Ruby 3.1系初のリリースである、Ruby 3.1.0 が公開されました。 + +{% assign release = site.data.releases | where: "version", "3.1.0" | first %} + + +## YJIT: New experimental in-process JIT compiler + +Ruby 3.1では、Shopifyが開発した新しいプロセス内JITコンパイラであるYJITをマージしました。 + +[2018年のRuby 2.6でMJITをマージ](https://www.ruby-lang.org/ja/news/2018/12/25/ruby-2-6-0-released/)して以来、そのパフォーマンスは年々改善され、去年には[Ruby3x3を無事達成](https://www.ruby-lang.org/ja/news/2020/12/25/ruby-3-0-0-released/)しました。比較的大規模なOptcarrotベンチマークでは輝かしい高速化を達成したMJITですが、一方で現実の業務アプリケーションの性能はこれまで改善出来ていませんでした。 + +近年Shopifyは彼らのRailsアプリケーションを高速化するため、Rubyに対して多くの貢献をしてきました。YJITはその中でも重要な貢献であり、Railsアプリケーションをさらに高速化するために開発されました。 + +MJITがメソッドベースのJITコンパイラであり、外部のCコンパイラを利用しているのに対し、YJITではBasic Block Versioningという技術を用いた独自のJITコンパイラをRuby内部に持っています。YJITの用いているLazy Basic Block Versioning (LBBC)では、まずメソッドの冒頭のみをコンパイルし、実行時に実際に値が渡されて引数や変数の値が明らかになってから残りをコンパイルするという手法を用いることで、動的プログラミング言語においても効率のよいJITを実現しています。詳細は [YJIT: a basic block versioning JIT compiler for CRuby](https://dl.acm.org/doi/10.1145/3486606.3486781) を参照ください。 + +これらの技術によって、YJITでは素早い起動と高速な実行を多くの実世界のアプリケーションに対して実現しており、railsbenchでは最大22%、liquied-renderでは39%の高速化を達成しています。 + +YJITはまだ実験的機能なため、デフォルトでは無効化されています。試してみたい場合には `--yjit` コマンドラインオプションを指定することでYJITを有効化出来ます。現在YJITはx86-64上のUnix系プラットフォームでのみ実行出来ます。 + +* https://bugs.ruby-lang.org/issues/18229 +* https://shopify.engineering/yjit-just-in-time-compiler-cruby +* https://www.youtube.com/watch?v=PBVLf3yfMs8 + +## debug gem: 新しいデバッガ + +完全に0から書き直したデバッガである [debug.gem](https://github.com/ruby/debug) が同梱されました。次のような特徴があります。 + +* デバッグ時の速度低下を極力生じないよう改善 +* リモートデバッグのサポート +* リッチなデバッガフロントエンドに対応(現在 VSCode と Chrome ブラウザに対応) +* マルチプロセス、マルチスレッドプログラムのデバッグに対応 +* カラフルな REPL +* そのほか、Record & Replay 機能やトレース機能など、様々な便利機能 + + + +Rubyにはこれまでも lib/debug.rb が同梱されていましたが、あまりメンテナンスされておらず、性能や機能に問題がありました。debug.gem はこれを完全に置き換えます。 + +## error_highlight: バックトレース中の詳細なエラー位置表示 + +error_highlightという組み込みgemが導入されました。これにより、バックトレース中でエラーが発生した詳細な位置が表示されます。 + +``` +$ ruby test.rb +test.rb:1:in `
': undefined method `time' for 1:Integer (NoMethodError) + +1.time {} + ^^^^^ +Did you mean? times +``` + +現在のところ、位置が表示されるのは`NameError`のみです。 + +このgemはデフォルトで有効になっています。`--disable-error_highlight`コマンドラインオプションを指定することで無効化できます。詳しくは[ruby/error_highlightリポジトリ](https://github.com/ruby/error_highlight)を見てください。 + +## IRB のオートコンプリートとドキュメント表示 + +IRB にオートコンプリート機能が実装され、コードを入力するだけで補完候補ダイアログが表示されるようになりました。Tab と Shift+Tab で上下に移動できます。 + +また、補完候補を選択している時に、ドキュメントがインストールされている場合、補完候補ダイアログの横にドキュメントダイアログが表示され、内容が一部表示されます。Alt+d を押すことでドキュメント全文を読むことができます。 + + + +## その他の主要な新機能 + +### 言語機能 + +* ハッシュリテラルやキーワード引数の値が省略可能になりました。 [Feature #14579] + * `{x:, y:}` は、`{x: x, y: y}` の糖衣構文です。 + * `foo(x:, y:)` は、`foo(x: x, y: y)` の糖衣構文です。 + +* パターンマッチ中のピン演算子に任意の式を書けるようになりました。 [Feature #17411] + +```ruby +Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a +#=> [[3, 5], [5, 7], [11, 13]] +``` + +* 一行パターンマッチで括弧が省略できるようになりました. [Feature #16182] + +```ruby +[0, 1] => _, x +{y: 2} => y: +x #=> 1 +y #=> 2 +``` + + +### RBS + +[RBS](https://github.com/ruby/rbs)はRubyプログラムの型を定義するための言語です。 + +3.0.0からは、次の様なアップデートがありました。 + +* ジェネリクスの型パラメータに制約を与えることができるようになりました。 ([PR](https://github.com/ruby/rbs/pull/844)) +* ジェネリックな型エイリアスが定義できようになりました。 ([PR](https://github.com/ruby/rbs/pull/823)) +* gemのRBSを管理するための`rbs collection`コマンドが導入されました。 ([doc](https://github.com/ruby/rbs/blob/master/docs/collection.md)) +* いろいろな組み込みクラスの型定義が追加、更新されました。 +* 多数のバグ修正と性能の改善が含まれています。 + +詳しくは[CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md)を確認してください。 + +### TypeProf + +TypeProfはRubyの静的型解析器です。型注釈のないRubyコードから、RBSのプロトタイプを生成します。詳しくは[ドキュメント](https://github.com/ruby/typeprof/blob/master/doc/doc.md)をご参照ください. + +Ruby 3.0.0からの主なアップデートは、"TypeProf for IDE"という実験的なIDEサポートです。 + +![Demo of TypeProf for IDE](https://cache.ruby-lang.org/pub/media/ruby310_typeprof_ide_demo.png) + +このVSCode拡張は、推定された(またはRBSファイルに手で明記された)メソッドのシグネチャを、各メソッド定義の上に表示します。 +また、NameErrorやTypeErrorを起こしうるコードを赤い下線で示します。 +さらに、メソッド名の補完(メソッド名の候補の表示)を行います。 +詳しくは[ドキュメント](https://github.com/ruby/typeprof/blob/master/doc/ide.md)をご参照ください。 + +また、数多くのバグ修正やパフォーマンス向上がなされています。 + +## パフォーマンスの改善 + +* MJIT + * For workloads like Rails, the default `--jit-max-cache` is changed from 100 to 10000. + The JIT compiler no longer skips compilation of methods longer than 1000 instructions. + * To support Zeitwerk of Rails, JIT-ed code is no longer cancelled + when a TracePoint for class events is enabled. + + +## その他の注目すべき 3.0 からの変更点 + +* 一行パターンマッチ(たとえば `ary => [x, y, z]`)が実験的機能ではなくなりました。 + +* 多重代入の評価順序が若干変更されました。[[Bug #4443]](https://bugs.ruby-lang.org/issues/4443) + * `foo[0], bar[0] = baz, qux` は、Ruby 3.0 では `baz`, `qux`, `foo`, `bar` という順序で評価されていましたが、Ruby 3.1 では `foo`, `bar`, `baz`, `qux` の順で表kされます。 + +* 可変幅アロケーション(Variable Width Allocation)が実装されました。現在は試験的にStringが対応しています。 [[Bug #18239]](https://bugs.ruby-lang.org/issues/18239) + +* Psych 4.0 では `Psych.load` が `safe_load` を利用するように変更されました。この挙動が影響ある場合は、従来の挙動である `unsafe_load` を利用する Psych 3.3.2 を移行パスとして利用できます。[[Bug #17866]](https://bugs.ruby-lang.org/issues/17866) + +## 標準添付ライブラリのアップデート + +* 以下の default gems のバージョンがアップデートされました。 + * RubyGems 3.3.3 + * base64 0.1.1 + * benchmark 0.2.0 + * bigdecimal 3.1.1 + * bundler 2.3.3 + * cgi 0.3.1 + * csv 3.2.2 + * date 3.2.2 + * did_you_mean 1.6.1 + * digest 3.1.0 + * drb 2.1.0 + * erb 2.2.3 + * error_highlight 0.3.0 + * etc 1.3.0 + * fcntl 1.0.1 + * fiddle 1.1.0 + * fileutils 1.6.0 + * find 0.1.1 + * io-console 0.5.9 + * io-wait 0.2.1 + * ipaddr 1.2.3 + * irb 1.4.1 + * json 2.6.1 + * logger 1.5.0 + * net-http 0.2.0 + * net-protocol 0.1.2 + * nkf 0.1.1 + * open-uri 0.2.0 + * openssl 3.0.0 + * optparse 0.2.0 + * ostruct 0.5.2 + * pathname 0.2.0 + * pp 0.3.0 + * prettyprint 0.1.1 + * psych 4.0.3 + * racc 1.6.0 + * rdoc 6.4.0 + * readline 0.0.3 + * readline-ext 0.1.4 + * reline 0.3.0 + * resolv 0.2.1 + * rinda 0.1.1 + * ruby2_keywords 0.0.5 + * securerandom 0.1.1 + * set 1.0.2 + * stringio 3.0.1 + * strscan 3.0.1 + * tempfile 0.1.2 + * time 0.2.0 + * timeout 0.2.0 + * tmpdir 0.1.2 + * un 0.2.0 + * uri 0.11.0 + * yaml 0.2.0 + * zlib 2.1.1 +* 以下の bundled gems のバージョンがアップデートされました。 + * minitest 5.15.0 + * power_assert 2.0.1 + * rake 13.0.6 + * test-unit 3.5.3 + * rexml 3.2.5 + * rbs 2.0.0 + * typeprof 0.21.1 +* 以下のライブラリが新たに bundled gems になりました。Bundler から利用する場合は Gemfile に明示的に指定してください。 + * net-ftp 0.1.3 + * net-imap 0.2.2 + * net-pop 0.1.1 + * net-smtp 0.3.1 + * matrix 0.4.2 + * prime 0.1.2 + * debug 1.4.0 + + +その他詳細については、[NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md) ファイルまたは[コミットログ](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }})を参照してください。 + +なお、こうした変更により、Ruby 3.0.0 以降では [{{ release.stats.files_changed }} 個のファイルに変更が加えられ、{{ release.stats.insertions }} 行の追加と {{ release.stats.deletions }} 行の削除が行われました](https://github.com/ruby/ruby/compare/v3_0_0...{{ release.tag }}#file_bucket) ! + +メリークリスマス、様々な機能が追加された Ruby 3.1 をぜひお楽しみ下さい! + +## ダウンロード + +* <{{ release.url.gz }}> + + SIZE: {{ release.size.gz }} + SHA1: {{ release.sha1.gz }} + SHA256: {{ release.sha256.gz }} + SHA512: {{ release.sha512.gz }} + +* <{{ release.url.xz }}> + + SIZE: {{ release.size.xz }} + SHA1: {{ release.sha1.xz }} + SHA256: {{ release.sha256.xz }} + SHA512: {{ release.sha512.xz }} + +* <{{ release.url.zip }}> + + SIZE: {{ release.size.zip }} + SHA1: {{ release.sha1.zip }} + SHA256: {{ release.sha256.zip }} + SHA512: {{ release.sha512.zip }} + +## Ruby とは + +Rubyはまつもとゆきひろ (Matz) によって1993年に開発が始められ、今もオープンソースソフトウェアとして開発が続けられています。Rubyは様々なプラットフォームで動き、世界中で、特にWebアプリケーション開発のために使われています。 From 9d266cfb613f62b4adb37cf857aca5e93a96171b Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Sat, 25 Dec 2021 20:41:25 +0900 Subject: [PATCH 0052/1025] Ruby 3 1 0 released 2 (#2766) * fix videos * Add stats to _data/releases.yml --- _data/releases.yml | 5 +++++ en/news/_posts/2021-12-25-ruby-3-1-0-released.md | 5 ++--- ja/news/_posts/2021-12-25-ruby-3-1-0-released.md | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/_data/releases.yml b/_data/releases.yml index a7a6341109..d84d0c9226 100644 --- a/_data/releases.yml +++ b/_data/releases.yml @@ -24,6 +24,11 @@ - version: 3.1.0 date: 2021-12-25 post: /en/news/2021/12/25/ruby-3-1-0-released/ + tag: ruby_3_1_0 + stats: + files_changed: 3123 + insertions: 551754 + deletions: 99153 url: gz: https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz zip: https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.zip diff --git a/en/news/_posts/2021-12-25-ruby-3-1-0-released.md b/en/news/_posts/2021-12-25-ruby-3-1-0-released.md index caf363cc42..9e80c9e092 100644 --- a/en/news/_posts/2021-12-25-ruby-3-1-0-released.md +++ b/en/news/_posts/2021-12-25-ruby-3-1-0-released.md @@ -71,11 +71,10 @@ The IRB now has an autocomplete feature, where you can just type in the code, an If documents are installed when you select a completion candidate, the documentation dialog will appear next to the completion candidates dialog, showing part of the content. You can read the full document by pressing Alt+d. -