Chris Shea
7/3/2007 5:03:00 PM
On Jul 3, 10:51 am, pietia <pietia....@gmail.com> wrote:
> Reacher wrote:
> > simple class:
>
> > class Myclass
> > def initialize(a)
> > @a = a
> > end
>
> > def prt
> > puts @a.to_s
> > end
>
> > def =(a)
> > @a = a
> > self
> > end
> > end
>
> > produces:
>
> > main.rb:23: syntax error, unexpected '='
> > def =(a)
> > ^
> > main.rb:28: syntax error, unexpected kEND, expecting $end
>
> hi !
>
> Maybe you should try this way:
>
> def MyClass=
> @a = a
> self
> end
>
> and the testing code :
>
> a = Myclass.new(10)
> b = a
> b.prt => 10 :)
>
> pietia !
I do not think this means what you think it means.
your MyClass= method is not being used on the second line of your
testing code "b = a". That's just the standard assignment operator.
That "testing" code evaluates the same without the MyClass= method
(that method is never called, and is, as it looks to me, nonsensical).
I think the correct answer is: you cannot override =
HTH,
Chris