Managing csv strings of unique values
I have a comma separated string of values whose order is not important, but the uniqueness of the values. I want to add values to a string and I get something like
"1,2,3,1".split(",").to_set << "1" << "4").to_a.join "," => "1,2,3,4"(
which is efficient but looks awful and goes string -> array -> set -> array -> which is no doubt inefficient too. What's an easy way to do this?
source to share