How do I join by new line

You need to use a double quote (“) instead of a single quote. So replace this: ‘\n’ with this: “\n” Read more about it here. You might want to use \r\n instead if you want your line-endings to be CRLF instead of LF (some Windows editors such as Notepad won’t see a LF linebreak).

Another way instead of escaping regex patterns?

Regexp.new(Regexp.quote(‘http://www.microsoft.com/’)) Regexp.quote simply escapes any characters that have special regexp meaning; it takes and returns a string. Note that . is also special. After quoting, you can append to the regexp as needed before passing to the constructor. A simple example: Regexp.new(Regexp.quote(‘http://www.microsoft.com/’) + ‘(.*)’) This adds a capturing group for the rest of the path.

Get response headers from Ruby HTTP request

The response object actually contains the headers. See “Net::HTTPResponse” for more infomation. You can do: response[‘Cache-Control’] You can also call each_header or each on the response object to iterate through the headers. If you really want the headers outside of the response object, call response.to_hash