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

+3


source to share


2 answers


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 ...

+6


source


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

+3


source







All Articles