From: Pedro Silva Date: 2008-09-01T03:42:41+09:00 Subject: Re: instance_eval/class_eval including/extending modules David, thanks for your reply. > I'm not sure what you mean by "ghost class". I think that might be an > unnecessary extra term. What I meant by "ghost class" was singleton class or eigenclass. I've already seen different names for the class that Ruby creates when we use instance_eval or define singleton methods. > Yes, and that's really part of the point of having both instance_eval > and class_eval. I don't think there's any advantage to merging them > into one behavior. Just choose the one you need in a given case. I'm not saying they should have the same behaviour in that sense, I was trying to say that they should have the same behaviour no matter what is the method visibility - private vs others. As matter of fact I think using instance_eval or class_eval with include/extend should have different results. SomeClass.instance_eval {include SomeModule} has the same result as SomeClass.class_eval {include SomeModule} > I don't really see the anomaly you're seeing, but let me outline the > rules that are followed (which, in the case of instance_eval, have > nothing to do with whether or not the object is a class), and maybe > that will clear it up or at least simplify it. The example above showed me the "special case" between private methods and other methods. Let me see if I can write an example that shows what I'm trying to say. I think the best way is using def vs define_method. SomeClass.instance_eval { def class_method; puts "Class Method"; end } SomeClass.instance_eval do define_method(:instance_method) {puts "Instance Method"} end SomeClass.class_method SomeClass.new.instance_method At least for me this is not something I would expect. When I define a method using instance_eval I expect to have a singleton method (class method in this case). The problem here has to do with self and what is the current class, self is still SomeClass so define_method creates an instance method, but because current class is the singleton class, using def is the same as creating a class method. I guess this happen because define_method is a private method. So in my opinion private methods have different treatment from regular methods. I hope I expressed myself in the right manner what I was trying to say (i'm not a native english speaker, portuguese actually :p). If you could tell me what you think about that I'll appreciate that. -- Posted via http://www.ruby-forum.com/.