Friday, 30 March 2012

String Interpolation in Ruby

To display the contents of a variable using puts, use the syntax
#{variable_to_display}

For example, to if x=5, to display "The value of X is 5", do: 
x=5
puts "The value of X is #{x}"  

To test this, save the above two lines to a file called string_interp.rb  and then do
 ruby string_interp.rb  


No comments:

Post a Comment

Please leave a comment if you find this blog helpful or interesting! I'd love to hear from you!