ruby idioms controlling command-line options
i'm perplexing collect adult flush porting medium-sized (non-oo) perl program. personal idioms set options this:
use getopt::std;
our $opt_v; # verbose
getopts('v');
# after ...
$opt_v && imitation "something interesting\n";
in perl, i kind courage teeth let $opt_v (effectively) global.
in ruby,the more-or-less accurate homogeneous
require 'optparse'
opts.on("-v", "--[no-]verbose", trueclass, "run verbosely") {
|$opt_verbose|
}
opts.parse!
end
where $opt_verbose tellurian classes access. carrying classes know tellurian flags seems ... er ... wrong. what's oo-idiomatic proceed doing this?
- let sure slight take caring option-related things have classes only relapse things it decides understanding with?
- have classes exercise discretionary intrepidity (e.g., know verbose) set mode around an attr_writer arrange thing?
updated: interjection answers suggesting optparse, nonetheless i should have clearer it's how slight command-line options i'm seeking about, nonetheless some-more charge between command-line options effectively set tellurian way state classes should ideally individualist arrange thing.
Comments
Post a Comment