? and ! are used in method names, but apparently cannot be used in variable names?
foo! = 2
=> SyntaxError: (irb):1: syntax error, unexpected '='
What is the reason?
? and ! are used in method names, but apparently cannot be used in variable names?
foo! = 2
=> SyntaxError: (irb):1: syntax error, unexpected '='
What is the reason?
? and ! are ruby operators, so they are not allowed in variable names. Otherwise, how will Ruby evaluate something like if (v!=2)
(expression that checks whether a variable v is not equal to 2) or something like v?1:0
(expression that will return 1 if v is truthy and 0 if its falsy)
UPDATE Another plausible reason is that Ruby treats names ending with ? and ! as methods