You need to join the values in a string:
"#{address['house_number']} #{address['street_name']},\n#{address['city']},\n#{address['post_code']}"
You could also improve the formatting by making this a helper method, and using a HEREDOC:
def formatted_address(address)
<<~ADDRESS
#{address['house_number']} #{address['street_name']},
#{address['city']},
#{address['post_code']}
ADDRESS
end
Usage:
address = {
"house_number" => 20,
"street_name" => "Mount Park Road",
"city" => "Greenfield",
"post_code" => "WD1 8DC"
}
puts formatted_address(address)
# => 20 Mount Park Road,
# Greenfield,
# WD1 8DC
solved How to merge values of a single hash?