Arguments
class Argy
def initialize = (@args = ARGV)
[:first, :second].each_with_index {|n,i|
define_method :"#{n}" do; @args[i] || nil; end
}
end
args = Argy.new
puts (args.first && args.second) ?
'two args (or more): %s & %s' % [args.first, args.second] :
(args.first) ? 'one arg: %s' % args.first : 'no arg'
Just a test on command line arguments.
The class is defining two methods (:first and :second), that returns ARGV[0] OR nil or ARGV[1] OR nil respectively.
Then a double ternary if is reporting ’two or more args’, ‘one arg’ or ’no args’.