From: Paul Brannan Date: 2001-11-13T00:43:30+09:00 Subject: [ruby-talk:24940] Re: Naming conventions On Tue, 13 Nov 2001, Hachenberger Peter wrote: > That's quite an interesting way to solve the problem, but i am curios about > the definition of the method Complex. As far as I have read, the naming > convention for methods tells us to begin a method name with a lowercase > Character. What happens here? Why does ruby know, that Complex is a method > call here and not the class name? A = 1 #=> 1 def A(*x); x; end #=> nil A(1) #=> [1] A 1 #=> [1] A 1, 2, 3 #=> [1, 2, 3] A(1, 2, 3) #=> [1, 2, 3] A #=> 1 A() #=> [] Looks like Ruby is treating the identifier just like any other: if it is by itself, then it tries to look it up as a variable first. If it is not by itself (with parens or arugments following), it is treated as a method call. This is evident in the following error messages: irb(main):001:0> foo NameError: undefined local variable or method `foo' for # from (irb):1 irb(main):002:0> foo() NameError: undefined method `foo' for # from (irb):2 As far as whether it is a good idea to have a method and a constant with the same name, imo this probably isn't a good idea. However, naming a method with a capital letter is commonly used to indicate that the method is a factory for some particular type (DelegateClass() is a factory for delegate classes, for example). Paul