From: Patrick Li Date: 2008-09-01T12:47:25+09:00 Subject: Re: instance_eval/class_eval including/extending modules Now that I have a firmer grasp on Ruby's object system, is it possible to combine some of these methods, so that they're easier to understand? Here's some changes that can be made: Let me know what you think -Patrick What it does: Combines eval/instance_eval/class_eval into one consistent method Combines include/extend into one consistent method Changes: eval(proc) -eval is now a method of Object. This ALWAYS sets self to the receiver object, and then evaluates proc. def myMethod -def is now a method of Module. This creates a method named myMethod() that can be called by instances of the receiver. Consequences: This means that if self is not a subclass of Module, you cannot call def. Instead I propose a metaclass method that returns an objects metaclass. So instead of: obj.instance_eval do def myMethod; end end you MUST do: obj.metaclass.instance_eval do def myMethod; end end include myModule -becomes a method of Object. This method puts the method definitions in myModule into the receiver object. -- Posted via http://www.ruby-forum.com/.