Ruby error - uninitialized OpenStruct constant (NameError)

I am trying to use optionparse ruby ​​to parse the arguments in my ruby ​​script. The problem is that I run a script like this bundler exec ruby ​​generation.rb --help I get the error "uninitialized constant OpenStruct (NameError)"

I believe, since I am running the script using bundle exec, I should not get 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) 
+6
source share
1 answer

You need to specify the OpenStruct source manually:

 require 'ostruct' 
+8
source

Source: https://habr.com/ru/post/974631/


All Articles