Equivalent of join () array for Set in Ruby?
What's wrong with set.to_a.join
?
Something to keep in mind: the documentation says that "A collection implements a collection of unordered values ββwithout duplicates." This means that the order is not guaranteed. For the method to_a
, the documentation states that "the order of the elements is undefined".
I'm not sure if it makes sense join
with these circumstances ...
source to share
There is no direct equivalent, as in a method that returns a string created by concatenating the elements of the set with a delimiter character, but you can use #to_a to convert it to an array and then call #join on that
http://ruby-doc.org/stdlib-2.2.2/libdoc/set/rdoc/Set.html#method-i-to_a
source to share