Thanks once again for the fast reply,

> I don't think there's any special case for private methods. They get
> called on 'self', just as they always do. And if you instance_eval a
> class, "def" does exactly what it does when you instance_eval any
> object: it creates a singleton method.

In my opinion define_method and def executed in the same context should 
have the same behaviour, but they don't. The reason def creates a 
singleton method is because the current class is set to the singleton 
class so there's where the method will be defined, but self remains the 
instance_eval receiver.

> Keep in mind that so-called "class methods" are essentially just
> singleton methods of instances of Class. (The only special case
> behavior is the fact that subclasses of class C can call class C's
> class methods.)

I know that, that's why I said singleton methods (class methods).

> Like most questions in Ruby, it comes down to: classes are objects too
> :-) I don't think instance_eval does anything special with classes.
> The only special thing you'd want to do is to be able to create
> instance methods, and class_eval handles that case.

I guess I was unable to express correctly my point. I know that 
class_eval lets create instance methods (that's why the receiver must be 
a class) and instance_eval singleton methods (on classes means class 
methods). My problem is having instance_eval with def creating singleton 
methods but with define_method creating instance methods. I expected to 
have def and define_method to have the same result on the same context, 
but they don't.
-- 
Posted via http://www.ruby-forum.com/.