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

  • Home
  • SEARCH
  • 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 5955967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:11:22+00:00 2026-05-22T18:11:22+00:00

The documentation for Ruby’s GetoptLong gave me the impression that it would remove the

  • 0

The documentation for Ruby’s GetoptLong gave me the impression that it would remove the parsed options from ARGV. Here’s the passage in question:

For example, if -a does not require an argument and -b optionally takes an argument,
parsing ’-a one -b two three’ would result in (’-a’,’’) and (’-b’, ‘two’) being processed as option/arg pairs, and ‘one’,’three’ being left in ARGV.

However, this doesn’t seem to be the case. Here is my program:

#!/usr/bin/env ruby

require "getoptlong"
opts = GetoptLong.new(
  ["--start", "-s", GetoptLong::REQUIRED_ARGUMENT],
  ["--base",  "-b", GetoptLong::REQUIRED_ARGUMENT]
)

puts ARGV

And here is the output:

$ number-photos --start 2 --base foo *
--start
2
--base
foo
aac-to-mp3
backup-wp-uploads
exiv-webcam-imgs
get-updates
music-to-lily
number-photos
ogg-to-mp3
rename-music
restore-uploads
resymlink
sprints
sync-jt
sync-st
timestamp
unix-names

(I did check that I’m on ruby 1.9.2.)

I could remove the options manually, but this would be a bit of a headache since, depending on how you pass them in, each could take up either one or two slots in the array (--base=foo vs. --base foo). It would be much more convenient if GetoptLong could remove them for me. Is there any way to do this?

  • 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-22T18:11:23+00:00Added an answer on May 22, 2026 at 6:11 pm

    I guess I understood that to mean that the item was not put in the getopt group.. it’s left in ARGV, as is everything else… Why would it modify ARGV?

    update eww. after some experimentation with the example in the documentation, it does not remove items from ARGV until the opts.each is run… it appear that removal is a side effect of visiting the item in opts.

    Very bad form. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate the Ruby documentation with hanna template. How to do that?
Busy learning Ruby... the documentation have an example: hello world.count(lo, o) that return 2
I'm trying to create a hash from an array and the documentation for http://ruby-doc.org/ruby-1.9/classes/Array.src/M000744.html
RDOC creates documentation from Ruby Source Files. Is there something similar for iOs? It's
So, ruby enterprise documentation states that all the values in the GC settings are
I read in some Microsoft documentation that PHP, together with Ruby on Rails, is
When I add has_secure_password to the model (inherited from ActiveRecord::Base), error stating that bcrypt-ruby
This question is similar to Why are methods in Ruby documentation preceded by a
What is the meaning, and where is the Ruby documentation for the syntax of:
Does anybody know some nice documentation about the ruby handsoap gem to get me

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.