Default values of Ruby variables
问题 I need to know the default values of variables in ruby. Global Variables: nil Instance Variables: ? Class Variables: ? Local Variables: ? I looked here, but all I could find is that global variables have a nil value. 回答1: You assign a local variable value at first assignment: local = 1 local1 + local # NameError: undefined local variable or method `local1' for main:Object Class variables are similar, if you use them without initialization, you get an error: class A @@a end # NameError: