Sometimes, the following causes a strange bug:
> nil || 4
NameError: undefined local variable or method ` 4' for main:Object
> nil || []
NameError: undefined local variable or method ` ' for main:Object
What is the reason?
You are accidentally typing Alt + Space on your Mac, which produces a non-breaking space. Ruby does not consider this as whitespace, but as part of a variable name. It then complains that the variable does not exist.
Some people like to remap Alt + Space to Space in order to prevent this typo.
I personally like to highlight invisible characters in my text editor, so I notice the typo immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With