From: _why Date: 2008-10-07T23:23:10+09:00 Subject: [ruby-core:19164] Re: [Feature #615] "with" operator On Tue, Oct 07, 2008 at 10:40:16PM +0900, Jim Weirich wrote: > I think there are two conversations going on in this thread. The original > proposal for 'with' was to allow methods without an explicit object target > to be sent to the object designated in the 'with' command. > > The second conversation is about temporarily adding methods to the current > object in order to get DSL-like capabilities. This was thread was > introduced by the suggestion of using the mixin/unmixin techniques. I really think this is a good idea for a `with` method, though. Rather than altering `self`, we could temporarily re-route methods. I'm saying that we take mixins a step further: beyond modules and on to objects, any object at all. Methods are just messages. And this would be the interception of those messages. Meanwhile, `self` and the ivars aren't messages (in that one can't manually route them -- you can't "def self".) And I think that's what's so surprising about instance_eval, when used as `with`. Rather than just routing messages to an object's public interface, you enter right into its private realm. Instance eval makes sense when you call it `instance_eval`, but it sometimes seems surprising when it is masked as something else. _why