-1

我对 capistrano 比较陌生。我想知道如何在 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​​ 类/方法?提前致谢。

4

1 回答 1

1

capistrano 中的所有内容都是红宝石,所以一切都很顺利:

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] 它将返回它,而不是截断它并存储在同一个变量中。

高温高压

于 2012-07-02T12:31:08.427 回答