是否有现成的库/方法可以将数组序列化为字符串,如下所示?
[] #=> ""
["Peter"] #=> "Peter"
["Peter", "Paul"] #=> "Peter and Paul"
["Peter", "Paul", "Mary"] #=> "Peter, Paul, and Mary" (with Oxford comma)
["Peter", "Paul", "Mary"] #=> "Peter, Paul and Mary" (without Oxford comma)
如果不是,那么最短的方法是什么?我想要这种形式:
class Array
def conjoin oxford_comma = true
...
end
end