# Issue with Getopt-declare incorrect parameter specification

**URL:** <https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512>\
**Category:** Ruby\
**Created:** [March 20, 2007, 11:21pm UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512 "2007-03-20T23:21:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [March 20, 2007, 11:21pm UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512/1 "2007-03-20T23:21:11Z")

</div>

Hi,

I’m having a weird problem with the “Getopt-declare” library. I wrote:

require ‘rubygems’  
require ‘Getopt/Declare’

pattern = “.\*”  
args = Getopt::Declare.new(%q@

-p some regexp; defaults to “.\*” (explanation)  
{  
pattern = regexp  
}  
@)

When I run: \<\< ruby script.rb -p ‘[a-c].\*’ \>\>

, I get the following error:

“Error: incorrect specification of ‘-p’ parameter”

Has someone an explanation for this ?

Thanks in advance,  
Frédéric

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [March 21, 2007, 11:47am UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512/2 "2007-03-21T11:47:11Z")

</div>

On 21 mar, 08:30, “gga” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> {
> 
> ```
> 
> VERSION 1.22  
> -p =\> “hello”  
> Unused:  
> PATTERN .\*

Thanks for the issue on the variable scope, but the error message  
appears when you use a more complex argument value than ‘hello’,  
i.e.

try.rb -p hello works fine

but

try.rb -p ‘[a-c].\*’ gives the error message

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [March 21, 2007, 8:36am UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512/3 "2007-03-21T08:36:23Z")

</div>

It seems to work for me with latest 1.22, albeit you should use  
$pattern or @pattern. Otherwise pattern is a local variable to the  
block.

require ‘rubygems’  
require ‘Getopt/Declare’

@pattern = “._"  
args = Getopt::Declare.new(%q%  
-p some regexp; defaults to "._” (explanation)  
{  
@pattern = regexp  
}  
%)

puts “VERSION #{Getopt::Declare::VERSION}”  
p args  
puts “PATTERN #@pattern”

> try.rb -p hello  
> VERSION 1.22  
> -p =\> “hello”  
> Unused:  
> PATTERN .\*

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [March 21, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512/4 "2007-03-21T17:11:51Z")

</div>

On 21 mar, 07:41, “Nexos” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > block.  
> > %)  
> > PATTERN .\*
> 
> Thanks for the issue on the variable scope, but the error message  
> appears when you use a more complex argument value than ‘hello’,  
> i.e.
> 
> try.rb -p hello works fine
> 
> but
> 
> try.rb -p ‘[a-c].\*’ gives the error message

Oh, yes. This is a bug I recently stumbled upon and has been fixed.

The problem is in Getopt/Declare.rb, around line 668. There’s a:

code \<\< ‘\b’

Just comment that out. I’ll be making a new release with that fix  
soon, but I am also adding a more complex Test::Unit test suite to  
catch those sort of errors.

---

<div class="post-metadata">

**Author:** ![Nexos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nexos](https://www.ruby-forum.com/u/Nexos)\
**Post date:** [March 21, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/issue-with-getopt-declare-incorrect-parameter-specification/89512/5 "2007-03-21T20:50:32Z")

</div>

On Mar 21, 5:08 pm, “gga” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > require ‘rubygems’  
> > > puts “VERSION #{Getopt::Declare::VERSION}”  
> > > Thanks for the issue on the variable scope, but the error message
> 
> The problem is inGetopt/Declare.rb, around line 668. There’s a:
> 
> code \<\< ‘\b’
> 
> Just comment that out. I’ll be making a new release with that fix  
> soon, but I am also adding a more complex Test::Unit test suite to  
> catch those sort of errors.

OK.  
Just tried it and it worked fine.

Thanks for explanation!

Regards,

Frédéric Delanoy
