I am using Ruby on Rails 3.2.2 and I would like to improve code below, maybe using some Ruby on Rails method.
I have an Array ["one", "two", "three"] for which I make
# From `Symbol`s to `String`s
array = [:one, :two, :three].map {|k| k.to_s}
# => ["one", "two", "three"]
and then (the attr_accessible method used below is just a sample method and only serves to give an idea of what I do; in production I use the “splat” array in a my custom method)
attr_accessible *array
# => attr_accessible "one", "two", "three"
Is there a better way to make the above? If so, how can I “convert” the ["one", "two", "three"] array in an “elegant” way?
In plain Ruby you can do
With the map_by_method gem you can do:
If you implement your custom method like this:
You can call it like