From: "Mauricio Fernández" Date: 2003-04-26T15:59:45+09:00 Subject: Re: yield self On Sat, Apr 26, 2003 at 10:06:10AM +0900, ahoward wrote: > On Sat, 26 Apr 2003, Joel VanderWerf wrote: > > > ahoward wrote: > > > > > > recently someone posted a very cool method which, given an object, would yield > > > a block of code with the value of self as that object. > > > > > > anyone remember this? i can't seem to find it... > > > > Do you mean instance_eval? > > no - i least i think i don't... perhaps i was dreaming? hope not, it was kind > of neat! Do you mean this? >> def with(object, &block) >> object.instance_eval(&block) >> end => nil >> with "1" do ?> puts "My length is #{length}" >> end My length is 1 => nil As usual, all rights reserved, etc; BTW I prefer cheques payable to bearer ;-) At least 80% of the profits will be reinvested in food for my brain (*) so that I can go on posting here. The way "new syntax" can be added so easily to Ruby never ceases to amaze me. (*) includes foodstuffs and "food for thought" -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com I'm telling you that the kernel is stable not because it's a kernel, but because I refuse to listen to arguments like this. -- Linus Torvalds