I often want to exclude the empty strings from an array of strings. A use case is to join an array of strings with
", ", removing the empty ones, as follows:
["Foo", "", "Bar"].reject(&:empty?).join(", ") # => "Foo, Bar"
In a similar situation with arrays of arrays, the empty ones can be excluded by using
[*[1, 2], *, *[3, 4]] # => [1, 2, 3, 4]
I would like to propose
String#to_a defined as follows:
class String def to_a; empty? ?  : [self] end end
Then we can do:
[*"Foo", *"", *"Bar"].join(", ")
Updated by matz (Yukihiro Matsumoto) almost 7 years ago
I understand your intention, but I think proposed behavior is bit awkward for
to_a of String class.
As you know
to_a stands for conversion to array, I don't think
 is natural conversion from strings.