2013-04-29 14 views

risposta

4

Sembra che si desidera exec che ultima riga, in quanto è, ovviamente, un comando di shell piuttosto che codice Ruby. Non è necessario interpolare due volte; una volta che lo farà:

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

Oppure, usando la variabile:

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

Nota che più di Ruby modo è quello di utilizzare i simboli anziché stringhe come chiavi:

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

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

Eccellente :) Grazie per la risposta. –

+0

Sei il benvenuto! –

2

Si potrebbe utilizzare le parentesi:

environments = { 
    'testing' => '11.22.33.44', 
    'production' => '55.66.77.88' 
} 
myString = 'testing' 
environments[myString] # => '11.22.33.44' 
Problemi correlati