The method itself gets.chompdoes not catch spaces. You will have to add them yourself.
Another Ruby way to do this is through a method join.
puts "So your full name is, #{[forename, middlename, surname].join(' ')}."
With David's suggestion to form a complete answer, use compactbefore joining to avoid an empty middlename and doubling the space.
puts "So your full name is, #{[forename, middlename, surname].compact.join(' ')}."
source
share