End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Shellwords#shelljoin
shelljoin(array)
lib/shellwords.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/shellwords.rb, line 194
def shelljoin(array)
array.map { |arg| shellescape(arg) }.join(' ')
end
Builds a command line string from an argument list, array.
All elements are joined into a single string with fields separated by a space, where each element is escaped for the Bourne shell and stringified using to_s.
Example
ary = ["There's", "a", "time", "and", "place", "for", "everything"] argv = Shellwords.join(ary) argv #=> "There\\'s a time and place for everything"
Array#shelljoin is a shortcut for this function.
Example
ary = ["Don't", "rock", "the", "boat"] argv = ary.shelljoin argv #=> "Don\\'t rock the boat"
You can also mix non-string objects in the elements as allowed in Array#join.
Example
output = `#{['ps', '-p', $$].shelljoin}`