Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Error - uninitialized constant OpenStruct (NameError)

Tags:

ruby

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)
like image 844
user1788294 Avatar asked Sep 01 '14 08:09

user1788294


1 Answers

You should require OpenStruct source manually:

require 'ostruct'
like image 59
Marek Lipka Avatar answered Sep 23 '22 16:09

Marek Lipka