diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-01-12 18:49:30 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-01-12 18:49:30 +0000 |
commit | d00fe54803361cb0a63325427f91a745a2488b72 () | |
tree | f26d4632bd7677fc389c43b27c89efd19f60df8a /lib/shellwords.rb | |
parent | c100aeb8384ce45a073741b649b14be6c211d2e6 (diff) |
* lib/shellwords.rb (Shellwords#shellescape): shellescape() now
stringifies the given object using to_s. * lib/shellwords.rb (Shellwords#shelljoin): shelljoin() accepts non-string objects in the given array, each of which is stringified using to_s. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/shellwords.rb | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -57,7 +57,8 @@ module Shellwords end # Escapes a string so that it can be safely used in a Bourne shell - # command line. # # Note that a resulted string should be used unquoted and is not # intended for use in double quotes nor in single quotes. @@ -77,6 +78,8 @@ module Shellwords # Multibyte characters are treated as multibyte characters, not # bytes. def shellescape(str) # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? @@ -101,7 +104,9 @@ module Shellwords end # Builds a command line string from an argument list +array+ joining - # all elements escaped for Bourne shell and separated by a space. # # open('|' + Shellwords.join(['grep', pattern, *files])) { |pipe| # # ... @@ -113,6 +118,11 @@ module Shellwords # # ... # } # def shelljoin(array) array.map { |arg| shellescape(arg) }.join(' ') end |