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 Enumerator::Yielder documentation #2273

Merged
merged 1 commit into from
Jun 2, 2020
Merged

Conversation

pocke
Copy link
Member

@pocke pocke commented May 24, 2020

Enumerator::Yielderのドキュメントを追加します。

このクラスはEnumerator.newからのみ使われるべきものなので、クラスの説明にも「直接使うものではありません」と書いています。
#1141

ただ、説明がないとEnumerator.newから使う時に迷ってしまうと思うので、ドキュメントを書くことは必要だと思っています。

また、合わせて Ruby 2.7で追加されたEnumerator::Yielder.to_procのドキュメントも書いています。 #2071
RDoc: https://docs.ruby-lang.org/en/2.7.0/Enumerator/Yielder.html#method-i-to_proc

RDocでは <<yield メソッドのドキュメントがありませんが、このドキュメントがないとEnumerator.newからどうやって使うべきか分かりづらいなと思ったので、あえて書きました。


ruby-jp slackの方で多少議論をしたので貼っておきます。

200525000056

END

enum = Enumerator.new do |y|
text.each_line(&y)
Copy link
Member Author

Choose a reason for hiding this comment

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

RDocの例は次のようになっています

enum = Enumerator.new { |y|
  Dir.glob("*.rb") { |file|
    File.open(file) { |f| f.each_line(&y) }
  }
}

これは実践的ではあるのですが、実行するには .rb ファイルが置かれている必要があるので、それに依存しないようにテキスト処理だけで済むようにしました

@znz znz merged commit 678daa6 into rurema:master Jun 2, 2020
@pocke pocke deleted the Enumerator-Yielder branch June 2, 2020 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants