From: Jos Backus Date: 2011-09-26T07:09:33+09:00 Subject: Re: Looking for better/familiar approach to command line opts --20cf3071cf94f8e86804adcb4b60 Content-Type: text/plain; charset=ISO-8859-1 Check out the getoptions gem by my friend Delaney Parker, it was modeled after Perl's Getopt::Long. Jos On Sep 25, 2011 2:24 PM, "Perl J." wrote: > Josh Cheek wrote in post #1023694: >> On Sun, Sep 25, 2011 at 4:03 PM, Josh Cheek >> wrote: >> >>>> use of AUTOLOAD, which some Perlers say is bad -- I say it's extremely >>>> >>>> >>>> values from the command line. If I said: >>>> Now how to do this in Ruby? Like I said, the OptParser seems WAY too >>>> :sPath => 's:', >>>> whether 'v' exists, true or false, into @verbose." Now how much more >>>> (I don't understand why a lot of d_m() examples use self.class.send()!!) >>>> def initialize( options ) >>>> end >>>> above. If the innards of the Options class use OptParser, fine. >>> program do what you want? >>> >>> >> >> Sorry, that should be like this: >> >> --- >> >> #!/usr/bin/env ruby -s >> options = { >> :source_path => $s, >> :dest_path => $d, >> :verbose => $v, >> } >> p options >> >> >> --- >> >> And you could invoke it like this >> >> $ ./script.rb -s=path/to/input.txt -d=path/to/output.txt -v >> {:source_path=>"path/to/input.txt", :dest_path=>"path/to/output.txt", >> :verbose=>true} > > Ehh, it's interesting and simple, for sure. But now I'm changing the > way I generally call and use DSLs I create. Generally I call as (as per > must Unix utils): > > $ myutil -f foo -b bar > > and not: > > $ myutil -f=foo -b=bar > > If the later were how I called things, then in my mind it would actually > be easier to just grab command line parameters and parse them myself on > the '=' symbol. > > Also, if -v isn't specified it becomes nil in the resulting hash, but I > see nil evals as false essentially, so that seems to still work. > > I might play with this some. I want a object instance, not a hash, but > I might be able to get there using this. It's much simpler, that's for > sure. > > -pj > > -- > Posted via http://www.ruby-forum.com/. > --20cf3071cf94f8e86804adcb4b60--