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 8799701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:23:41+00:00 2026-06-14T00:23:41+00:00

I have a Ruby script, called foobar.rb , which takes multiple parameters. I want

  • 0

I have a Ruby script, called foobar.rb, which takes multiple parameters.

I want to (optionally) be able to specify an array of integers on the command line and be able to process them as a single option. I think that my command line would look something like this:

foobar.rb [1,2,3]

On a scale of 1-10 my knowledge of Ruby is probably around a 6. Just enough to know that there’s probably an easy way to accomplish this, but not enough to know what it is or even where to look in the docs.

How can I parse this single comma-separated list of integers and end up with an Array in the code? I would prefer an idomatic, 1-liner solution that doesn’t require the addition of any external libraries, if such a solution exists.

  • 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-06-14T00:23:42+00:00Added an answer on June 14, 2026 at 12:23 am

    I would use optparse for it myself, like this:

    require 'optparse'
    
    options = {}
    
    OptionParser.new do |opts|
      opts.banner = "Usage: #{$0} [options]"
    
      opts.on("-a", "--argument a,b,c", Array, "Array of arguments") { |a| options[:array] = a.map { |v| v.to_i } }
    end.parse!
    
    puts options.inspect
    
      => {:array=>["1", "2", "3", "4"]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby script called foo.rb, and I want to run it within
Well, the title say it all. I have a ruby script I want running
I have a controller called 'exposures' which I created automatically with the script/generate scaffold
I have a Ruby script which downloads YouTube Insight reports for specific videos within
I have a Ruby script which wants to determine its absolute path in order
I have Ruby script that creates a proxy so that I can make HTTP
so i have ruby script that simply writes to a test.txt file with hello
I have a ruby script that opens a browser. I have it set to
I have a Ruby script (1.8.7) that sets up its own interactive shell for
I have a ruby script that does a few perforce operations (through the scripting

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.