ruby - Improve parsing '*arg' values -


i know if there better way (that is, less coding) have same output following code:

# arg = :a, :b, :c  output = args.to_a.flatten.compact.map(&:to_sym) # => [:a, :b, :c] 

i use above code parse arguments passed method in way

`method_name(:a, :b, :c)`. 

i don't see need to_a, flatten or compact.

you can .map(&:to_sym) if want convert strings symbols. if you're accepting symbols, args contains want.

def method_name(*args)    p args.map(&:to_sym) end  method_name(:a, "b", :c) 

output

[:a, :b, :c] 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -