module PS class Command ARR_ARGS = { :format => '-o ', :gid => '-G ', :group => '-g ', :uid => '-u ', :pid => '-p ', :tty => '-t ', :user => '-U ', :flag => '-' } attr_reader *ARR_ARGS.keys.collect {|key| key.to_s+'s'} FLAG_LIST = 'AaCcEefhjlMmrSTvwXx'.split('').freeze def initialize opts={} ARR_ARGS.keys.each do |arg| arr = opts[arg] || [] instance_variable_set "@#{arg}s", arr end end def to_s cmd = [] parse_formats! ARR_ARGS.each do |var,trigger| sep = var == :flags ? nil : ',' vals = instance_variable_get("@#{var}s").uniq cmd << trigger+vals.join(sep) unless vals.empty? end "ps "<