From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-03-22T03:44:17+09:00 Subject: Re: Proposal: new operator: '<-' (for assignments) In article <003701c2ef8a$e05cd220$0300a8c0@austin.rr.com>, Hal E. Fulton wrote: >----- Original Message ----- >From: "Phil Tomson" >Newsgroups: comp.lang.ruby >To: "ruby-talk ML" >Sent: Friday, March 21, 2003 2:41 AM >Subject: Re: Proposal: new operator: '<-' (for assignments) > > >> In article <2003320223415.480988@PADD>, >> Austin Ziegler wrote: >> >On Fri, 21 Mar 2003 11:20:27 +0900, Phil Tomson wrote: >> >> Now of course, I could have allowed access to @val by declaring an >> >> attr_accessor, but in many cases I don't want to expose that >> >> information or make users of the class have to remember the name >> >> of the variable 'val'. It just seems much cleaner in many cases to >> >> have an assignment operator. Up till now I've been overriding '<<' >> >> to do this, but now I've run into a case where I'd like to pass on >> >> operators to the underlying value (@val in the example above) >> >> using method_missing so the underlying value can be shifted (and >> >> since '<<' is overriden, that's kind of tough). >> > >> >Array, String, and Hash use #replace to do this. >> > >> >> Perhaps, but I'm looking for an operator because: >> 1) it's shorter >> 2) the intent of '<-' is pretty clear (in fact it's often used for this in >> pseudocode) > >Interesting, but I'm not sure it improves the >language enough to justify the changes. > >It would surprise me if Matz liked this. Yeah, I didn't figure the chances were too great, but it was worth a try anyway ;-) > >Another possibility might be to establish a standard >accessor name as Javascript does and as I did with >my super-iterator class. > > class Array > def value=(val) > self.replace val > end > end > >It would surprise me if you liked this. :) Well, I'll probably just stick with using '<<' as a synonym or 'assign' and alias the original '<<' shift functionality of Fixnum to 'shift' Phil