module Sip class CmdOpts < Hash def set(*k) k.each { |key| self[key] = nil } end def to_s(prefix=nil, suffix=nil) opts = map { |k,v| if v.nil? (k.length > 1) ? "--#{k}" : "-#{k}" else (k.length > 1) ? "--#{k}=#{v}" : "-#{k} #{v}" end }.join(" ") [(prefix.nil? ? "" : prefix), opts, (suffix.nil? ? "" : suffix)].select { |v| v != "" }.join(" ") end end end