What do $undefined and $end refer to in Ruby?
-
06-09-2019 - |
Question
I used a backslash to continue a Ruby statement on the next line.
print abc \
+ def
I added a space after the backslash, because I like to blow things up, and, sure enough, I got an error:
unexpected $undefined, expecting $end
I assume $undefined is a global variable that means anything the compiler sees that it doesn't recognize - in this case the space after the backslash.
Is $end a global variable that refers to the "end of line" character?
Are these globals just global in my program or are they more global than that? Just how global are they?
Solution
Those are not global variables. That is just notation used by the parser. $undefined
appears to mean a blank space or token of no meaning. $end
is the end of a line or statement.
OTHER TIPS
I'd bet the $ is just a shorthand that the parser/lexer uses to symbolise a token, and not an actual usable variable.
$undefined is referring to the lexer token created by "\ " -- it isn't syntactically valid ruby.
$end lexer token for the end of the file.
-- MarkusQ