ruby中argv
Interpolation
is about using expressions and values inside a string. For example, consider a variable named a which contains 4 and variable b containing 6. Now, we have to print 4 * 6 = 24
Interpolation
是关于在字符串中使用表达式和值。 例如,假设一个名为a的变量包含4,而一个变量b包含6。现在,我们必须打印4 * 6 = 24
a * b = a*b. Will this work?
Nope. It returned an unexpected result. We need the values of a, b and a*b to be printed. Now, Interpolation
comes into picture. Using Interpolation
, we can include expression and values inside strings.
不。 它返回了意外的结果。 我们需要打印a , b和a * b的值。 现在, Interpolation
成为现实。 使用Interpolation
,我们可以在字符串中包含表达式和值。
To Interpolate the value of a, do the following: puts " #{a} "
It returned the value of a instead of "a" as a string. Likewise, we have to do the same for the variable b and the expression a*b.
它以字符串形式返回a的值而不是“ a” 。 同样,我们必须对变量b和表达式a * b进行相同的操作 。
Ruby evaluates the value of the variable or an expression given between the curly braces.
Ruby计算变量的值或花括号之间的表达式。
#{a*b}
#{a*b}
Ruby, evaluates the value of a*b and interpolates into string.
Ruby,计算a * b的值并将其内插到字符串中。
插值字符串: (Interpolating Strings:)
Consider a variable with a value.
考虑具有值的变量。
person = "Sachin Tendulkar";
person = "Sachin Tendulkar";
Now, we have to display "I love Sachin Tendulkar".
现在,我们必须显示“我爱Sachin Tendulkar”。
We've expected "I love Sachin Tendulkar" but it displayed "I love person". Now, let's interpolate the variable person
.
我们期望“我爱Sachin Tendulkar”,但显示“我爱人” 。 现在,让我们对变量person
插值。
翻译自: https://www.studytonight.com/ruby/interpolation-in-ruby
ruby中argv