# Gem and optparse : help needed

**URL:** <https://www.ruby-forum.com/t/gem-and-optparse-help-needed/73782>\
**Category:** Ruby\
**Created:** [October 27, 2006, 12:31am UTC](https://www.ruby-forum.com/t/gem-and-optparse-help-needed/73782 "2006-10-27T00:31:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [October 27, 2006, 12:31am UTC](https://www.ruby-forum.com/t/gem-and-optparse-help-needed/73782/1 "2006-10-27T00:31:06Z")

</div>

Hello, I want to use optparse on a gem packaged bin/ file  
(eg/usr/lib/ruby/gems/1.8/gems/mypackage/bin/foo)

The goal is to make foo usable from the command line without anything  
else except the name of the file (no .rb, no ruby ./something)  
So, the Ruby file in bin/ directory don’t have .rb extension and  
includes this as the first line of code  
#!/usr/bin/ruby

So does several packages I’ve seen (rcov for example)

But for a reason I don’t understand the code above doesn’t works…  
From the stdlib doc, tested on a mygem/bin/foo :

#!/usr/bin/ruby  
require ‘optparse’

options = {}  
OptionParser.new do |opts|  
opts.banner = “Usage: example.rb [options]”

```
 opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
   options[:verbose] = v
 end

```

end.parse!

p options  
p ARGV

foo --verbose  
displays  
{}  
[]

Why ? What’s wrong ??

Thanks

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [November 7, 2006, 10:45am UTC](https://www.ruby-forum.com/t/gem-and-optparse-help-needed/73782/2 "2006-11-07T10:45:29Z")

</div>

Hi,

At Fri, 27 Oct 2006 07:30:34 +0900,  
Zouplaz wrote in [ruby-talk:222142]:

> foo --verbose  
> displays  
> {}  
> []

It did display {:verbose=\>true} as expected.

Does gem’s wrapper do something wicked?
