I know I can do this in Ruby:
['a', 'b'].map do |s| s.to_sym end
and get this:
I'm looking for a more concise way to do it, without using a block. Unfortunately, this doesn't work:
['a', 'b'].map #to_sym
Can I do better than with the initial code?
Read a bit about Symbol#to_proc:
['a', 'b'].map &:to_sym
# Either will result in [:a, :b]
This works if you're using Ruby 1.8.7 or higher, or if you're using Rails - ActiveSupport will add this functionality for you.
['a', 'b'].map(&:to_sym) is shorter