2013-04-29 58 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' 
相關問題