[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: [PATCH] OptionParser < Hash

From: "greg weber" <eegreg@...>
Date: 2006-09-13 10:40:04 UTC
List: ruby-core #8856
This is great, Nobu!

I added lazy switch creation with new(), so if a program is called
without any arguments or exits before calling the parsing functions,
it will run much faster.  Also, I pass the result hash into the new
block if user desires to assign keys to it in addition to the
defaults.

Perhaps next we can make the exclusive switches.  Also, I hope I can
get help from someone for my rdoc-optparse patching.

Greg Weber

Attachments (1)

optparse_lazy.diff (1.04 KB, text/x-diff)
750c750
<   def initialize(banner = nil, width = 32, indent = ' ' * 4)
---
>   def initialize(banner = nil, width = 32, indent = ' ' * 4, &block)
758c758
<     yield self if block_given?
---
>     @setup = block_given? ? (lambda &block) : nil
1210c1210,1218
<   def parse_in_order(argv = default_argv, setter = nil, &nonopt)
---
>   def parse_in_order(argv = default_argv, result = nil, &nonopt)
>     return argv if argv[0].nil?
>     # initialize switches
>     if @setup.arity == 2
>       @setup.call(self, result)
>     else
>       @setup.call(self)
>     end
> 
1227c1235
<             setter.call(sw.switch_name, val) if setter
---
>             result[sw.switch_name] = val if result
1257c1265
<             setter.call(sw.switch_name, val) if setter
---
>             result[sw.switch_name] = val if result
1318c1326
<   def getopts(argv, single_options = nil, *long_options)
---
>   def getopts(argv = default_argv, single_options = nil, *long_options)
1342c1350
<     parse_in_order(argv, result.method(:[]=))
---
>     parse_in_order(argv, result)

In This Thread