Removing "n" from a string depending on certain cases

I have this string that i build using the outputs of various functions which each return strings:

[resource_name, 
 duration, 
 project_name, 
 total_hours, 
 details, 
 booker, 
 user_details].join("n") 

Each of these functions return a string of information which, as a whole, builds a notification message. What i’m struggling to implement is each string is joined by a new line character, but sometimes the functions return an empty string, because the information isn’t specified. For example if no project_name is specified, the string will be empty.

How do i make that whole line be deleted, rather than having an empty string followed by a new-line?, because that doesn’t look presentable.


Source: ruby

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.