当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby Shellwords.shelljoin用法及代码示例


本文简要介绍ruby语言中 Shellwords.shelljoin 的用法。

用法

shelljoin(array)
也别名为:join

从参数列表 array 构建命令行字符串。

所有元素都连接到一个字符串中,字段由空格分隔,其中每个元素都为 Bourne shell 转义并使用 to_s 进行字符串化。

ary = ["There's", "a", "time", "and", "place", "for", "everything"]
argv = Shellwords.join(ary)
argv #=> "There\\'s a time and place for everything"

Array#shelljoin 是此函数的快捷方式。

ary = ["Don't", "rock", "the", "boat"]
argv = ary.shelljoin
argv #=> "Don\\'t rock the boat"

您还可以在 Array#join 中允许的元素中混合非字符串对象。

output = `#{['ps', '-p', $$].shelljoin}`

相关用法


注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Shellwords.shelljoin。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。