Reputation: 25378
I have the following:
arr = [["1/31/2012 8:00 PM"]]
Right now, to get that string I end up doing arr.first.first
...which just seems awkward.
What's a more direct way to get 1/31/2012 8:00 PM
?
Upvotes: 1
Views: 94
Reputation: 17803
Your code seems the correct way to do it, but, you can also do
arr.to_s
=> "1/31/2012 8:00 PM"
But be cautious. This will concatenate the elements in the array into a single string, if more than one element is present in the array
[["this", "is"]].to_s
=> "thisis"
[["this", "is"], ["test"]].to_s
=> "thisistest"
Upvotes: 0
Reputation: 13739
It depends on your array purpose, you have several options:
arr[0][0]
is is equal to arr.first.first
. But I think arr.first.first
is normal solutionarr.flatten.first
arr
with which you will be able to query for this data more naturally like meeting.nearest # => "1/31/2012 8:00 PM"
.Upvotes: 4