Undefined local variable or method for main: Object

Sometimes the following strange error occurs:

> 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?

+7
ruby whitespace
source share
1 answer

You accidentally typed Alt + Space on your Mac, which creates inextricable space . Ruby does not see this as a space, but as part of the variable name. He then complains that the variable does not exist.

Some people like to reassign Alt + Space to Space to prevent this typo.

I personally like to highlight invisible characters in a text editor, so I immediately notice a typo.

+8
source share

All Articles