flux flux - 2 years ago 56
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?"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download