In Ruby, you can use periods (.) and double colons (: :) to call a method. The two methods are different only when the called method name starts with an uppercase letter.
When you call a method using the double colon (: :) method, if the first letter of the method name is in upper case and there is no parentheses during the call
1. If the caller is a class or module, the method will be mistakenly treated as a constant;
2. If the caller is a class instance, a syntax error is returned;
LabCodeAs follows:
Class cattr_accessor: constclassconst = 3def m1puts "hello" enddef C: M1 # class methods can be defined using the dot and double colon "C. m1 "enddef barputs" bar "enddef C: barputs" C. bar "endendc = C. NEWC. m1c: M1 # The class instance can call the class instance method puts "--------" C. m1 # class can call class method C: m1puts "--------" C. bar # C: bar # error, syntax error puts "--------" C. const = 1 puts "C. const = # {C. const} "# C: const = 2 # error, syntax error # puts" C. const = # {C: const} "# errorc: bar () # OKC. bar # OK # C: bar # error, uninitialized constant C: bar (nameerror) puts "C: classconst =#{ C: classconst }"