Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

rubyのキーワード引数のあるメソッドをYardで書く方法

内容

意外とググっても出なかったのでメモ。

rubyのキーワード引数(keyword parameters)があるメソッドのパラメータドキュメントをYardで書く場合どうするか。

答え

rubyでよく使われるHashをオプションとして引数に渡す場合、下記のように @option が使われるが、

# @param [Hash] opts the options to create a message with.
# @option opts [String] :subject The subject
# @option opts [String] :from ('nobody') From address
# @option opts [String] :to Recipient email
# @option opts [String] :body ('') The email's body
def send_email(opts = {}) end

キーワード引数の場合は、普通に @param を利用するのが正解のようだ。

Note: For keyword parameters, use @param, not @option.

なので、下記のようになる。

# @param [String] subject The subject
# @param [String] from ('nobody') From address
# @param [String] to Recipient email
# @param [String] body ('') The email's body
def send_email(subject: nil, from: nil, to: nil, body: nil) end
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
4
Help us understand the problem. What are the problem?