3 ms·
> What i don't like about Ruby is that undefined variables can be accessed without error (just like javascript) What do you mean by this? Can you give an examp
by nateberkopec 11y ago
> What i don't like about Ruby is that undefined variables can be accessed without error (just like javascript)
What do you mean by this? Can you give an example?
- cremno 11y agoAccessing undefined/unitialized global or instance variables (like: @i) is not an error and nil will be returned. With -w a warning will be emitted. The weird class variables must be initialized. Local variables (lexically scoped) must be defined and are default-initialized to nil. (Global and class variables are usually not used.)
- yedpodtrzitko 11y agoanother example: > a=a => nil but then: > a=b NameError: undefined local variable or method `b' for main:Object