flux flux - 1 year ago 43
Ruby Question

Using a method to puts variables

I want to use

method and
a string with the user input.

puts "What is your name?"
name = gets.chomp
puts "Hi, " name.capitalize "how are you?"

Here is the error after line 2:

syntax error, unexpected tIDENTIFIER, expecting $end puts "Hi, "
name.capitalize "how are you?"

Answer Source

You need to use string interpolation. Here is a RubyMonk tutorial you may enjoy.

puts "Hi, #{name.capitalize}, how are you?"