# Help with OptionParser

**URL:** <https://www.ruby-forum.com/t/help-with-optionparser/125277>\
**Category:** Ruby\
**Created:** [January 7, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/help-with-optionparser/125277 "2008-01-07T20:21:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [January 7, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/help-with-optionparser/125277/1 "2008-01-07T20:21:46Z")

</div>

Hello all,

I’m needing some help with OptionParser. I’m wanting to use it to parse  
a  
string rather than ARGV, but when I pass the parse method a string of  
options, i get the following error:

undefined method `shift’ for “–help”:String (NoMethodError)

Is there a way I can format the string of options so OptionParser can  
use  
it?

Thanks! – BTR

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [January 7, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/help-with-optionparser/125277/2 "2008-01-07T20:27:03Z")

</div>

> I’m needing some help with OptionParser. I’m wanting to use it to parse a  
> string rather than ARGV, but when I pass the parse method a string of  
> options, i get the following error:
> 
> undefined method `shift’ for “–help”:String (NoMethodError)
> 
> Is there a way I can format the string of options so OptionParser can use  
> it?

AFAIK the easiest solution is to give it an array which contains just  
one string.

–  
Giles B.

Podcast: [http://hollywoodgrit.blogspot.com](http://hollywoodgrit.blogspot.com)  
Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com](http://giles.tumblr.com)

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [January 7, 2008, 8:53pm UTC](https://www.ruby-forum.com/t/help-with-optionparser/125277/3 "2008-01-07T20:53:27Z")

</div>

Sweet! Thanks.
