2013-04-29 57 views

回答

4

它看起来像你想exec最后一行,因为它显然是一个shell命令,而不是Ruby代码。你不需要插入两次;一旦会做:

exec("rsync -ar [email protected]#{environments['testing']}:/htdocs/") 

或者,使用变量:

exec("rsync -ar [email protected]#{environments[current_environment]}:/htdocs/") 

注意的是,更多的Ruby的方法是使用符号,而不是字符串作为关键字:

environments = { 
    :testing => '11.22.33.44', 
    :production => '55.66.77.88' 
} 

current_environment = :testing 
exec("rsync -ar [email protected]#{environments[current_environment]}:/htdocs/") 
+0

优秀的:)感谢你的回答。 – 2013-04-29 22:52:01

+0

非常欢迎! – 2013-04-29 22:57:08

2

你会使用括号:

environments = { 
    'testing' => '11.22.33.44', 
    'production' => '55.66.77.88' 
} 
myString = 'testing' 
environments[myString] # => '11.22.33.44' 
相关问题