in Education by
I declare steps that need to be done in order to install wordpress in an array in the beginning of my ruby script $wordpress_cmds = [ "mkdir -p #{$web_root}#{$web_directory}#{$web_url}/public_html", "cp -R #{$wordpress_current}/* #{$web_root}#{$web_directory}#{$web_url}/public_html", "chown -R www-data:www-data #{$web_root}#{$web_directory}#{$web_url}", ] Some of the variables are updated later on. Is there any way to get the latest values of all variables that are in the array when accessing the arrya? Let's say that if my code is like I always get the initial value of the array not the one I want (with updated variables inside) $web_root = '=====' $wordpress_cmds = ["#{$web_root}"] puts $wordpress_cmds[0] $web_root= "new value" puts $wordpress_cmds[0] $web_root.replace("new value") puts $wordpress_cmds[0] JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
No, string interpolation is one-time operation. It modifies the string by substituting values and that's it. However, with a slightly modified code you can do like this: $web_root = '=====' $wordpress_cmds = [lambda{"mkdir -p #{$web_root}#{$web_directory}#{$web_url}/public_html"}] puts $wordpress_cmds[0].call $web_root= "new value" puts $wordpress_cmds[0].call $web_root.replace("new value") puts $wordpress_cmds[0].call Output: ===== new value new value Here instead of string you put a function into array. That function will return an actual value of your variable. So, you have to do $wordpress_cmds[0].call instead of $wordpress_cmds[0] to actually invoke it.

Related questions

0 votes
    Let's say I have one variable, directory_list, which I define and set in a ruby_block named get_directory_list. Can ... woohoo" end end Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    In Ruby, Dir.glob("**/*.rb") (for instance) doesn't traverse symlinked directories. Is it ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the numbers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    This question exist only because of pure curiosity. Not a homework. Find the fastest way to find two ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    first..sorry for my poor english and my big noob question..the problem is... I need create a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    As the title suggests, I'm just looking for a way of pressing a button in Shoes without clicking ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a Jenkins Slave (A Windows PC) which has the JAVA_HOME environment variable. I updated the Java ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    What is true about functions : I) Functions are objects II) Can be assigned to a variable III) Can be anonymous IV) Return value type has ... , III 3. I, II, III, IV 4. I, II, IV...
asked Feb 25, 2021 in Technology by JackTerrance
0 votes
    What is true about functions : I) Functions are objects II) Can be assigned to a variable III) Can be anonymous IV) Return value type has ... , III C) I, II, III, IV D) I, II, IV...
asked Oct 9, 2020 in Technology by JackTerrance
0 votes
    (i) x=5, y=6,2=20 Q8) Consider the following statements and describe the output/statement required: ... multiple assignment statements. Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
0 votes
    Assume that I am using Tableau Desktop and have a live connection to Cloudera Hadoop data. I need to press ... the visualization every x minutes instead of pressing F5 everytime?...
asked Oct 30, 2020 in Technology by JackTerrance
0 votes
    Views stores the data and you can refresh it on timely bases a. False b. True...
asked Feb 19, 2023 in Technology by JackTerrance
0 votes
    Can we place an Excel file in a shared location and use it to develop a report and refresh it in regular intervals?...
asked Oct 30, 2020 in Technology by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
...