我对卡利斯特拉诺很新。我想知道如何在capistrano任务中对变量进行子串。
虽然这给了我在 irb
中的期望ruby-1.9.2-p136 :012 > release_path = "12345678910"
=> "12345678910"
ruby-1.9.2-p136 :019 > release_path[-6..-1]
=> "678910"
在capistrano任务中 什么都不做
namespace :namespacename do
task :taskname do
release_path = "1234678910"
release_path[-6..-1]
# output is still "12345678910"
puts release_path
end
end
任何人如何在capistrano任务中对变量使用ruby类/方法?提前谢谢。
答案 0 :(得分:1)
这都是卡皮斯特拉诺的红宝石,所以一切都真的如此:
namespace :namespacename do
task :taskname do
release_path = "1234678910"
release_path[-6..-1] #<---- NO!!!
# output is "678910"
puts release_path[-6..-1] #<---- YEAH BOY!!!
release_path = release_path[-6..-1]
puts release_path # output is "678910"
release_path[-3..-1] # does nothing because "910" is returned into thin air
puts release_path[-3..-1] # output is "910"
puts release_path[-3..-1][-2..-1] # output is substring of substring "10"
end
end
使用子字符串范围语法[x ... y]它将返回它,而不是截断它并存储在同一个变量中。
HTH