我如何从
传递a = "blog.posts.[activity]-It's-raining"
到
blog.posts.\[activity\]-It\'s-raining.md
那是带有转义符号的a
吗?通常,必须在控制台(linux)中读取字符串a
答案 0 :(得分:2)
您可以使用Shellwords.escape
:
require "shellwords"
a = "blog.posts.[activity]-It's-raining"
puts Shellwords.escape(a)
这导致:
$ ruby foo.rb
blog.posts.\[activity\]-It\'s-raining