Ruby question: concatenating strings in check-stats.rb


Look at this plugin:

Near the end, there’s a line that reads:

message += "#{msg} " unless s == 0

It concatenates msg chunks into a big message string. Later, when the string is printed out to the handler, all the msg chunks are separated by whitespace. Okay.

If I change the line like this:

message += “#{msg}\n” unless s == 0

then message is printed out as a series of msg chunks separated by newline.

But if I do this:

message += “#{msg}#{config[:separator]}”

and pass the separator as a command-line option (–separator “\n”) then the chunks are printed out separated by a backslash and the letter n.

Why “\n” works when hardcoded, but doesn’t work when passed as a command-line option?

How can I pass some custom separators as an option and make them work correctly? In most cases, it would be either: whitespace, or newline, or comma, etc.