Project

General

Profile

Misc #14753

Add documentation for "into" option of optparse

Added by pocke (Masataka Kuwabara) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
[ruby-core:87004]

Description

This patch adds an example code for into option into the optparse documentation.
into keyword argument has been added with https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/53444 . However documentation for usage of the option does not exist.

I have two purposes.
Firstly, I'd like to add an example for the option. into option is very useful, but I guess many people do not know it. So I think we should add an example for it.

Secondly, I'd like to add an example that has on method calls without a block.
The documentation does not have an example that has on method call without a block. So I cannot know usage of on method without a block from the documentation.
So I usually wrote on method with a block. It is redundant.
For example:

require 'optparse'

params = {}
OptionParser.new do |opts|
  opts.on('-a VAL') { |v| v } # It is redundant.
  opts.on('-b VAL', &:itself) # It is redundant also, and I feel it is not non-intuitive. 
  opts.on('-c VAL')           # It is cool!
end.parse!(into: params)
p params

Files

patch (992 Bytes) patch pocke (Masataka Kuwabara), 05/12/2018 05:41 AM

Associated revisions

Revision 5c0e6cc8
Added by nobu (Nobuyoshi Nakada) over 1 year ago

optparse.rb: [DOC] about into: option

  • lib/optparse.rb: add documentation for "into" option of #parse and family, which stores options to a Hash. [ruby-core:87004] [Misc #14753]

From: pocke (Masataka Kuwabara) kuwabara@pocke.me

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63410
Added by nobu (Nobuyoshi Nakada) over 1 year ago

optparse.rb: [DOC] about into: option

  • lib/optparse.rb: add documentation for "into" option of #parse and family, which stores options to a Hash. [ruby-core:87004] [Misc #14753]

From: pocke (Masataka Kuwabara) kuwabara@pocke.me

Revision 63410
Added by nobu (Nobuyoshi Nakada) over 1 year ago

optparse.rb: [DOC] about into: option

  • lib/optparse.rb: add documentation for "into" option of #parse and family, which stores options to a Hash. [ruby-core:87004] [Misc #14753]

From: pocke (Masataka Kuwabara) kuwabara@pocke.me

History

Updated by shevegen (Robert A. Heiler) over 1 year ago

\o/

It's nice to see people improving on optparse - the awkward documentation
has been one reason for me to avoid it.

#2

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63410.


optparse.rb: [DOC] about into: option

  • lib/optparse.rb: add documentation for "into" option of #parse and family, which stores options to a Hash. [ruby-core:87004] [Misc #14753]

From: pocke (Masataka Kuwabara) kuwabara@pocke.me

Also available in: Atom PDF