[#70252] Re: [ruby-cvs:58640] nobu:r51492 (trunk): node.c: NODE_ALLOCA for ALLOCV — Eric Wong <normalperson@...>
Besides possible backwards compatibility, can we drop volatile
3 messages
2015/08/05
[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...
Issue #11420 has been reported by Koichi Sasada.
11 messages
2015/08/06
[#70337] Re: [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI
— Eric Wong <normalperson@...>
2015/08/11
Nice. Thank you guys for looking into this.
[#70349] Re: [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI
— Eric Wong <normalperson@...>
2015/08/12
Btw, did you consider using flexible array to avoid extra malloc
[#70355] Re: [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI
— Юрий Соколов <funny.falcon@...>
2015/08/12
I thought to suggest to embed hash_id_table directly into places when it is
[#70356] Re: [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI
— SASADA Koichi <ko1@...>
2015/08/12
On 2015/08/13 4:29, Юрий Соколов wrote:
[#70358] Re: [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI
— Eric Wong <normalperson@...>
2015/08/12
SASADA Koichi <ko1@atdot.net> wrote:
[#70509] [Ruby trunk - Misc #11276] [RFC] compile.c: convert to use ccan/list — ko1@...
Issue #11276 has been updated by Koichi Sasada.
3 messages
2015/08/21
[#70639] the undefined behavior of an iterator if it is modified inside of the block to which it yields — Daniel Doubrovkine <dblock@...>
(this is my first time e-mailing list list, so apologies for any misstep :)
4 messages
2015/08/31
[ruby-core:70431] [Ruby trunk - Feature #11191] Add #to_h method to OptionParser
From:
nobu@...
Date:
2015-08-17 13:46:15 UTC
List:
ruby-core #70431
Issue #11191 has been updated by Nobuyoshi Nakada.
https://github.com/nobu/ruby/tree/feature/11191-optparse-into
----------------------------------------
Feature #11191: Add #to_h method to OptionParser
https://bugs.ruby-lang.org/issues/11191#change-53842
* Author: Lee Jarvis
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
Simply collecting configuration values is a very popular use for OptionParser. Code like this is quite common:
~~~ruby
config = {}
opts = OptionParser.new do |o|
o.on "-h", "--host=HOST", "hostname" do |h|
config[:host] = h
end
o.on "-p", "--port=PORT", "port", Integer do |p|
config[:port] = p
end
o.on "-v", "--verbose" do
config[:verbose] = true
end
o.on "-q", "--quiet" do
config[:quiet] = true
end
end
opts.parse!
# do something with config values
~~~
This boilerplate is one of the reasons I built Slop: https://github.com/leejarvis/slop
I'd like to add a `to_h` method to OptionParser which returns a Hash containing the switch name and switch argument values. This would reduce the above example to:
~~~ruby
opts = OptionParser.new do |o|
o.on "-h", "--host=HOST", "hostname"
o.on "-p", "--port=PORT", "port", Integer
o.on "-v", "--verbose"
o.on "-q", "--quiet"
end
~~~
With this example, the output would look something like:
~~~ruby
opts.parse %w(--host localhost --port 8000 --verbose)
puts opts.to_h #=>
{:host=>"localhost", :port=>8000, :verbose=>true, :quiet=>nil}
~~~
I've attached a patch that implements this functionality in quite a basic way. I'm very keen to hear what others think.
---Files--------------------------------
0001-Add-to_h-method-to-OptionParser.patch (2.97 KB)
--
https://bugs.ruby-lang.org/