From: Pit Capitain Date: 2008-10-08T02:57:45+09:00 Subject: [ruby-core:19176] Re: [Feature #615] "with" operator 2008/10/7 Jim Weirich : > But if I understand the implementation, you are not intercepting the > messages. They still go to the original object. All you've done is > redefine the messages. How do you plan to redirect them to the object given > in the 'with' statement? Maybe I see it too simplistically, but if all that's wanted in this discussion is a possibility to get access to the outer scope, then all you have to do is to capture it in a local variable: def with( obj, &blk ) obj.instance_eval( &blk ) end outer_self = self with "sample" do puts "inner self: #{self.class} #{self}" puts "outer self: #{outer_self.class} #{outer_self}" end which results in inner self: String sample outer self: Object main > When doing a DSL for (primarily) > non-programmers, I have no problems going the instance_eval route. When > writing a library to be used by programmers, I prefer straightforward > semantics that can easily reasoned about. I think using instance_eval in the way shown above you get both: an easy to use syntax for end-users and access to the outer scope for programmers, plus straightforward semantics. BTW: I would love to be able to uninclude modules, but I think it isn't needed for this use case. Regards, Pit