logo       

Re: ambiguity between local variable assignment and writter method: msg#01143

lang.ruby.general

Subject: Re: ambiguity between local variable assignment and writter method

[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>
Google Custom Search

News | FAQ | advertise