From: Greg McIntyre Date: 2003-11-19T22:12:28+09:00 Subject: Re: x.f! RCR After thinking more about this, I can see why certain methods have a ! version available and others don't. Or I think I do. It's about data encapsulation, to some extent. If I have class Foo attr :bar def initialize @bar = [1,2,3] end end foo = Foo.new I want to allow foo.bar.map!{|x| x*2 } Because it's convenient and it seems legitimate. But I don't want things which will change@bar's class. Like foo.bar.join!(', ') would be bad because then @bar would be something completely different all of a sudden and the poor Foo object and its clients might not like that. More generally, I guess this is about repeatable methods. There's a word for that, I've forgotten. i.e. You can do this: foo.bar.map!{|x| x*2 }.map!{|x| x*2 } But you can't do this: foo.bar.join!(', ').join!(', ') Hence join! is not defined. Am I on the right track? Greg McIntyre wrote: > It bugs me that some methods have a ! on the end and some don't. It > seems very arbitrary and inconsistent to me. And the same for ?. I'd > like it if ! was a special keyword or operator or something, so that > > x.f! > > was expanded to this > > (x = x.f) > > if x#f! was not already defined (so that in-place algorithms retained > their efficiency). Has this already been suggested? > > -- > Greg McIntyre ======[ greg@puyo.cjb.net ]===[ http://puyo.cjb.net ]=== -- Greg McIntyre ======[ greg@puyo.cjb.net ]===[ http://puyo.cjb.net ]===