10

I am trying to use optionparse of ruby to parse the arguments to my ruby script. Problem is when I am running the script like this bundler exec ruby generation.rb --help I am getting error "uninitialized constant OpenStruct (NameError)"

I believe since I am running the script using bundle exec I should not be getting this error. What am I doing wrong.

require 'optparse'

    def parse(args)

        options = OpenStruct.new
        options.dir = '../somerepo'
        opts = OptionParser.new do |opts|
            opts.banner = "Usage: generation.rb [options]"
            opts.separator ""
            opts.separator "Options:"


            opts.on("--temp c_name", "abcddd") { |abc|
                options.temp = abc
            }


            opts.separator ""
            opts.on_tail("-h", "--help", "Show this message") {
                puts opts
                exit
            }

            opts.parse!(args)
            return options

        end
    end


    inputOpts = parse(ARGV)

1 Answer 1

20

You should require OpenStruct source manually:

require 'ostruct'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.