在声明ruby散列时,我尝试使用其他变量的值。这些值现在正像我预期的那样被转义。我怎么才能解决这个问题?
变量
ipa_url、名称、版本和包标识符
码
data = {
plist: {
dict: {
key: 'items',
array: {
dict: {
key: %w('assets','metadata'),
array: {
dict: [{ key: %w('kind','url'),
string: %w('software-package',
"#{ipa_url") },
{ key: %w('kind','url'),
string: %w('display-image',"#{icon_url.to_s}") },
{ key: %w('kind','url'),
string: %w('full-size-image',
"#{icon_url}") }],
dict: { key: %w('bundle-identifier','bundle-version',
'kind','title'),
string: %w("#{bundle-identifier}","#{version}",
'software',"#{name}")
}
}
}
}
}
}
}发布于 2015-01-09 19:39:17
%w标识符用于从空格分隔的文本中创建数组:
%w(this is a test)
# => ["this", "is", "a", "test"]如果您想在那里使用字符串插值,则应该使用%W:
variable = 'test'
%W(this is a #{variable})
# => ["this", "is", "a", "test"]发布于 2015-01-09 18:18:05
蜘蛛侠详细介绍了这一点,但为了达到这个目的,下面是详细的分类:
%Q(无插值)
[6] pry(main)> hey
=> "hello"
[7] pry(main)> hash = { 'hi' => %q("#{hey}", 'how are you') }
=> {"hi"=>"\"\#{hey}\", 'how are you'"}%Q(插值和反斜杠)
[8] pry(main)> hash = { 'hi' => %Q("#{hey}", 'how are you') }
=> {"hi"=>"\"hello\", 'how are you'"}%(插值和反斜杠)
[9] pry(main)> hash = { 'hi' => %("#{hey}", 'how are you') }
=> {"hi"=>"\"hello\", 'how are you'"}%W(interpolation)作为Uri显示:
[7] pry(main)> hash = { 'hi' => %W(#{hey} how are you) }
=> {"hi"=>["hello", "how", "are", "you"]}https://stackoverflow.com/questions/27866569
复制相似问题