How do I combine map with to_s?
ruby
Solution
This works fine, but don't do it!
ids_as_string = Bar.where(:some_id => N).map(&:another_id).map(&:to_s)
It looks cool for sure, but think about it, you are doing two maps. A map is for looping over an array, or something else, and will operate in each position, retrieving a new array, or something else, with the results.
So why do two loops if you want to do two operations?
ids_as_string = Bar.where(:some_id => N).map {|v| v.another_id.to_s}
This should be the way to go in this situation, and actually looks nicer.
Problem
I am using Mongoid and retrieving a bunch of `BSON::ObjectId` instances. Ideally, I'd like to convert them to strings upon retrieval. What's the correct syntax? It can be done in two lines like this: ``` foo = Bar.where(:some_id => N).map(&:another_id) ids_as_strings = foo.map(&:to_s) ``` What's the proper Ruby way to chain `to_s` after the map invocation above?