Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:12:48+00:00 2026-05-29T06:12:48+00:00

I want to have params like this: program dothis –additional –options and: program dothat

  • 0

I want to have params like this:

program dothis --additional --options

and:

program dothat --with_this_option=value

and I can’t get how to do that. The only thing I managed to do is to use params with -- at the beginning.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:12:48+00:00Added an answer on May 29, 2026 at 6:12 am

    To handle positional parameters using OptionParser, first parse the switches using OptionParser and then fetch the remaining positional arguments from ARGV:

    # optparse-positional-arguments.rb
    require 'optparse'
    
    options = {}
    OptionParser.new do |opts|
      opts.banner = "Usage: #{__FILE__} [command] [options]"
    
      opts.on("-v", "--verbose", "Run verbosely") do |v|
        options[:verbose] = true
      end
    
      opts.on("--list x,y,z", Array, "Just a list of arguments") do |list|
        options[:list] = list
      end
    end.parse!
    

    On executing the script:

    $ ruby optparse-positional-arguments.rb foobar --verbose --list 1,2,3,4,5
    
    p options
    # => {:verbose=>true, :list=>["1", "2", "3", "4", "5"]}
    
    p ARGV
    # => ["foobar"]
    

    The dothis or dothat commands can be anywhere. The options hash and ARGV remains the same regardless:

     # After options
     $ ruby optparse-positional-arguments.rb --verbose --list 1,2,3,4,5 foobar
    
     # In between options
     $ ruby optparse-positional-arguments.rb --verbose foobar --list 1,2,3,4,5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that I want other processes to be able to call
I have a code like this: public static void ToUpperCase(params Control[] controls) { foreach
So basically I have a controller. something like this def show @user = User.find[:params[id]]
I have a hash that looks something like this: params = { :irrelevant =>
I would like to have a route like this get users/sms_confirmation/:sms_confirmation_code => users#sms_confirmation bind
want to have a Hyperlink-Button in a gridView in which I can display a
I want to have a text box that the user can type in that
I have an object Tasks with a model like this has_many :notes, :validate =>
Imagine I have this scenario in my Controller: def nr_1 = params.first_nr def nr_2
My code looks like this, and it works: if Target.find_by_shrunk(params[:shrunk]) @target = Target.find_by_shrunk(params[:shrunk]) else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.