From: "David A. Black" Date: 2004-08-24T11:03:23+09:00 Subject: Re: *with* block? Hi -- On Tue, 24 Aug 2004, Zach Dennis wrote: > I am looking for a structure like: > > my_obj = boxWidget.new > with my_obj do > x = 0 > y = 10 > width = 100 > height = 100 > end > > instead of having to say > > my_obj = boxWidget.new > my_obj.x = 0 > my_obj.y = 10 > my_obj.width = 100 > my_obj.height = 100 > > > > Can you do this already? If not....anyone support an RCR for it besides me? Every assignment to a bare identifier (x = 0) is parsed as an assignment to a local variable. If you want to call a "="-style method, you have to give the receiver explicitly. So I don't think a "with" keyword would add much to what you can already do with instance_eval: my_obj = BoxWidget.new my_obj.instance_eval do self.x = 0 self.y = 0 ... end which then isn't a whole lot better than my_obj.x = 0 and so on. Another thing people sometimes do is: my_obj = BoxWidget.new do |bw| bw.x = 0 bw.y = 10 ... end which can be nice because it packages the initialization with the creation of the object, but of course it only works if BoxWidget#initialize yields the new object. David -- David A. Black dblack@wobblini.net