From: "Jan E." Date: 2012-03-30T22:12:36+09:00 Subject: Re: Why z = Complex(1,2) rather than z = Complex.new(1,2)? Robert Klemme wrote in post #1054170: > Do you get that at the calling site or at the definition site? I get the message when I define the method. Robert Klemme wrote in post #1054170: > Jan E. wrote in post #1054047: >> Another problem is that constants and methods have different lookup >> algorithms, which doesn't allow you to put the conversion method for a >> subclass into the same containing module/class (unless you use qualified >> names all the time). > > Can you show an example of what you cannot do? At the moment I don't > see the limitation. As long as you're on top level, you can define a class and the corresponding method on the same level: #### A = Class.new def A() A.new end p A p A() #### But when the class is inside a module, you cannot define the method in this module and access it in the same way as you access the class: #### module M A = Class.new def self.A() A.new end class B def test p A # this works p A() # this doesn't end end end b = M::B.new b.test #### Of course, there's nothing strange about this behaviour. Methods simply cannot access "outer methods". But in this context, I find the different lookup algorithms counterintutive. You'd have to qualify the method name or define it in a different place (like the top level). Robert Klemme wrote in post #1054170: > There are far worse "warts" as you call them, for example class > variables. Sure. -- Posted via http://www.ruby-forum.com/.