Skip to content

Instantly share code, notes, and snippets.

@nhance
Created October 3, 2012 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhance/3826929 to your computer and use it in GitHub Desktop.
Save nhance/3826929 to your computer and use it in GitHub Desktop.
Misleading heredoc can fool even expert ruby coders
EOF = 0
def grocery(list)
puts "We've stolen #{list}"
end
def list
"your credit card"
end
string = string
string <<EOF
grocery list
EOF
puts string.inspect
$ ruby string_heredoc.rb
We've stolen your credit card
"\000"
$ ruby string_heredoc.rb
string_heredoc.rb:12: uninitialized constant EOF (NameError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment