|
Re: ambiguity between local variable assignment and writter method: msg#01213lang.ruby.general
Very nice analogy! And good example, too. ----- Original Message ----- From: "Massimiliano Mirra" <list@xxxxxxxxxxxxxxxxxx> > [On calling setter from inside the class] > > > Consider this: > > > class HalfDouble > attr_reader :double, :half > > def double=(val) > @double = val > @half = @double / 2 > end > > def half=(val) > @half = val > @double = @half / 2 > end > end > > hd = HalfDouble.new > > hd.double = 4 > > p hd.half > p hd.double > > > Then try to replace @double= with self.double= and @half= with > self.half= and see what happens... > > > Maybe I'm just being naive, but even though a one uses tongue to > translate his thought for the outside world, and ears to translate > what comes from the outside world into thought, I see nothing wrong in > using just thought for internal communication. > > In other words, to me, using setters from inside the class seems a lot > like talking to oneself. :-) > > > Massimiliano
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: ambiguity backtrack - accessors and persistent locals, Gavin Sinclair |
|---|---|
| Next by Date: | Re: Data_Make_Struct Considered Dangerous?, William Djaja Tjokroaminata |
| Previous by Thread: | Re: ambiguity between local variable assignment and writter method, Massimiliano Mirra |
| Next by Thread: | Problems installing FLTK on Windows, Axel Friedrich |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |