Equivalent of join () array for Set in Ruby?
Is there an equivalent array join()
for class Set
in Ruby
? or is it best to just decapitate my own in the Set class?
http://ruby-doc.org/stdlib-2.2.2/libdoc/set/rdoc/Set.html
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 ...
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