Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample code of Array#to_ary #719

Merged
merged 3 commits into from Nov 22, 2017

Conversation

tagucch
Copy link
Contributor

@tagucch tagucch commented Oct 18, 2017

@znz
Copy link
Member

znz commented Oct 19, 2017

to_ary の例なのに to_a になってしまっているようです。

@sho-h
Copy link
Member

sho-h commented Oct 21, 2017

以下は雑なサンプルですけど、to_aと比較できる内容でセットで追加しちゃうのがいいかもしれません。

--- to_a ...

...

例:

  class MyArray < Array; end
  a1 = Array[1, 2, 3, 4]
  a2 = MyArray[1, 2, 3, 4]
  [a1.to_a, a1.to_a.class]     # => [[1, 2, 3, 4], Array]
  [a2.to_a, a2.to_a.class]     # => [[1, 2, 3, 4], Array]

@see [[m:Array#to_ary]]

--- to_ary ...

...

例:

  class MyArray < Array; end
  a1 = Array[1, 2, 3, 4]
  a2 = MyArray[1, 2, 3, 4]
  [a1.to_ary, a1.to_ary.class] # => [[1, 2, 3, 4], Array]
  [a2.to_ary, a2.to_ary.class] # => [[1, 2, 3, 4], MyArray]

@see [[m:Array#to_a]]

@tagucch
Copy link
Contributor Author

tagucch commented Oct 26, 2017

なるほど。確かにto_aとto_aryの違いが分かるほうがいいですよね。ありがとうございます。

@tagucch
Copy link
Contributor Author

tagucch commented Nov 9, 2017

上記アドバイスしていただいたサンプルを参考に、Array#to_aryArray#to_aの両方のサンプルを追加し、違いが分かるようにしました。
ご確認よろしくお願いいたしますm(_ _)m

@@ -1606,10 +1606,38 @@ sort_by の破壊的バージョンです。
self を返します。ただし、Array のサブクラスのインスタンスに対して呼ばれた時は、
自身を Array に変換したものを返します。

例:

Class SubArray < Array; end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classclass ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classですね、ご指摘ありがとうございます。

--- to_ary -> self

self をそのまま返します。

例:

Class SubArray < Array; end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも。

@tagucch
Copy link
Contributor Author

tagucch commented Nov 20, 2017

@znz レビューしていただいてありがとうございますm(_ _)m

classの部分を修正しました。

@znz znz merged commit 6a7e168 into rurema:master Nov 22, 2017
@znz
Copy link
Member

znz commented Nov 22, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants