Your understanding is incorrect. When you store the content "hello\nworld" into a variable, the \n is interpreted literally. Only if you invoke tools such as printf or echo with -e flag, they expand those backslash sequences when printing to console.
In your case, you want to pass the variable to the environment with newline character expanded, suggest using the ANSI C style $'...' quoting operator inof ksh93, now supported by several other shells including bash and zsh for this:
env FOO=$'hello\nworld' ruby -e 'puts ENV["FOO"]' Or if portability is an issue, a trivial solution is to put those newlines where you want them
f="hello world" env FOO="$f" ruby -e 'puts ENV["FOO"]'