本文简要介绍ruby语言中  Array.join  的用法。
用法
join →new_stringjoin(separator = $,) → new_string返回转换后连接数组元素形成的新字符串。对于每个元素element
- 
如果 element不是kind_of?(Array),则使用element.to_s。
- 
如果 element是kind_of?(Array),则使用递归element.join(separator)。
如果没有参数,则使用输出字段分隔符 $, 进行连接:
a = [:foo, 'bar', 2]
$, # => nil
a.join # => "foobar2"使用字符串参数 separator ,使用该分隔符连接:
a = [:foo, 'bar', 2]
a.join("\n") # => "foo\nbar\n2"递归连接嵌套数组:
a = [:foo, [:bar, [:baz, :bat]]]
a.join # => "foobarbazbat"相关用法
- Ruby Array.join()用法及代码示例
- Ruby Array.push用法及代码示例
- Ruby Array.hash用法及代码示例
- Ruby Array.to_a用法及代码示例
- Ruby Array.to_h用法及代码示例
- Ruby Array.to_s用法及代码示例
- Ruby Array.array + other_array用法及代码示例
- Ruby Array.take()用法及代码示例
- Ruby Array.reject!用法及代码示例
- Ruby Array.flatten!用法及代码示例
- Ruby Array.reject用法及代码示例
- Ruby Array.repeated_permutation()用法及代码示例
- Ruby Array.index()用法及代码示例
- Ruby Array.pack()用法及代码示例
- Ruby Array.rassoc(obj)用法及代码示例
- Ruby Array.values_at()用法及代码示例
- Ruby Array.each用法及代码示例
- Ruby Array.fetch用法及代码示例
- Ruby Array.flatten用法及代码示例
- Ruby Array.sort用法及代码示例
- Ruby Array.unshift()用法及代码示例
- Ruby Array.reverse用法及代码示例
- Ruby Array.array | other_array用法及代码示例
- Ruby Array.rotate()用法及代码示例
- Ruby Array.rindex用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Array.join。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
