Do a calculation in interpolation block : Interpolating « Language Basics « Ruby






Do a calculation in interpolation block


"I've set x to #{x = 5; x += 1}."       # => "I've set x to 6."
x                                       # => 6

 








Related examples in the same category

1.Interpolation
2.Interpolating Variables in Double-Quoted Strings
3.Number value Interpolation
4.The #{100 * 5} interpolates the result of 100 * 5 (500) into the string at that position
5.You can interpolate strings too
6.Constant Interpolation
7.Call integer.to_s and Interpolation
8.Use string method in interpolation
9.Using expression substitution
10.Add extra # sign to interpolation
11.Compare string after interpolation
12.Put class into interpolation block
13.Escape theinterpolation string
14.Interpolation in Here document