Created
October 3, 2012 13:35
-
-
Save nhance/3826929 to your computer and use it in GitHub Desktop.
Misleading heredoc can fool even expert ruby coders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EOF = 0 | |
def grocery(list) | |
puts "We've stolen #{list}" | |
end | |
def list | |
"your credit card" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = string | |
string <<EOF | |
grocery list | |
EOF | |
puts string.inspect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby string_heredoc.rb | |
We've stolen your credit card | |
"\000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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