Ruby 中有好几种不同类型的标识符

  • constants
  • global variables
  • instance variables
  • class variables
  • local variables
  1. # 变量名的首字母是大写的
  2. Pi = 3.14
  3. module Math # module name is capitalized
  4. PI = 3.1415926 # constant is capitalized
  5. class DoubleFloating # class name is capitalized
  6. @@num_objs = 0
  7. def initialize
  8. @@num_objs += 1
  9. @value = 0.0
  10. end
  11. end
  12. end

内建变量

nil, true, false, self