Skip to content

Commit

Permalink
respond to 関連の翻訳を修正
Browse files Browse the repository at this point in the history
cf. #2773 (comment)

> respond to `foobar`のような部分は、「foobar **メソッド**を持つオブジェクト」「オブジェクトに foobar メソッドを定義する」と直接的に表現するのはどうだろうか(そして注釈を削除し、respond toの香りを無くす)
> * respond toをあまり大事にする必要がないと思うため:
>
>   * トレイトやインターフェイスのないRubyでは、ダックタイピング的に実装することになるが、そこまでくると、直接的に「メソッドを持つ」でいいと感じる
>   * ココをうまく使いこなすのに、内部の挙動である`Object#respond_to?`まで踏み込んで理解する必要性は薄く(個人的見解)、却って(初心者寄りの読者は特に)混乱を招きそう
  • Loading branch information
sanfrecce-osaka committed Jan 6, 2023
1 parent ed29996 commit b00f3fc
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions refm/doc/spec/pattern_matching.rd
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ users.any? {|user| user in {name: /B/, age: 20..} } #=> true
Array/Find/Hash パターンの中に 『<subpattern>』 と書かれている場所では任意のパターンをネストさせることができます。

#@# Array patterns and find patterns match arrays, or objects that respond to +deconstruct+ (see below about the latter).
Array パターン と Find パターン は配列か deconstruct を持つオブジェクトにマッチします。(deconstruct については後ほど説明します)
Array パターン と Find パターン は配列か deconstruct メソッドを持つオブジェクトにマッチします。(deconstruct については後ほど説明します)

#@# Hash patterns match hashes, or objects that respond to +deconstruct_keys+ (see below about the latter). Note that only symbol keys are supported for hash patterns.
Hash パターン はハッシュか deconstruct_keys を持つオブジェクトにマッチします。(deconstruct_keys については後ほど説明します) Hash パターン で利用できるキーはシンボルのみです。

#@# 原文にないが補足のため追加
※ deconstruct や deconstruct_keys を扱う際の『〜を持つ』の定義は [[m:Object#respond_to?]] と同様です。
Hash パターン はハッシュか deconstruct_keys メソッドを持つオブジェクトにマッチします。(deconstruct_keys については後ほど説明します) Hash パターン で利用できるキーはシンボルのみです。

#@# An important difference between array and hash pattern behavior is that arrays match only a _whole_ array:
Array パターン と Hash パターン の挙動の重要な違いは Array パターンは配列の 「全ての」 要素がマッチする必要があるということです。
Expand Down

0 comments on commit b00f3fc

Please sign in to comment.