I would like to know if there is a better way (that is, less coding) to have the same output as the following code:
# arg = :a, :b, :c
output = args.to_a.flatten.compact.map(&:to_sym)
# => [:a, :b, :c]
I use the above code to parse arguments passed by a method in this way
`method_name(:a, :b, :c)`.
I don’t see any need for
to_a,flattenorcompact.You can just do
.map(&:to_sym)if you want to convert strings to symbols. If you’re only accepting symbols, justargscontains what you want.Output