From: Neubyr Neubyr Date: 2012-07-04T07:07:20+09:00 Subject: passing ARGV to class methods I have been writing command-line programs using a pattern similar to described here - http://blog.toddwerth.com/entries/5 . Below is a quick and dirty code snippet based on this pattern. #!/usr/bin/env ruby require 'ostruct' require 'optparse' class MyPrinter def initialize(arguments) @arguments = arguments # Set defaults @options = OpenStruct.new end def parse_options opts_obj = OptionParser.new do |opts| opts.on('-h', '--help') { @options.help = true } end opts_obj.parse!(@arguments) end def process_options output_help if @options.help end def output_help puts 'Use Google!' end def run parse_options process_options end end p = MyPrinter.new(ARGV) p.run I was wondering if I really need to pass ARGV to MyPrinter's initialize method. The ARGV is anyway available to the class so I think it doesn't need to be passed and can be used directly during option parsing step - 'opts_obj.parse!(ARGV)' . But I am not sure if it's a good practice or not. Any tips? - thanks, neubyr -- Posted via http://www.ruby-forum.com/.