Misc #14753

Add documentation for "into" option of optparse

Added by pocke (Masataka Kuwabara) about 2 years ago. Updated about 2 years ago.



This patch adds an example code for into option into the optparse documentation.
into keyword argument has been added with . 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 = {} 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


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

Also available in: Atom PDF