[BUG?] Object property

  • Thread starter Fitzgerald,Greg
  • Start date
F

Fitzgerald,Greg

------_=_NextPart_001_01C479A4.87C345E3
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable


Is this a bug?

def myProp=3D (var)
@var =3D var
end

def myProp
@var
end

myProp =3D "local"
myProp # =3D> "local"
self.myProp # =3D> nil

self.myProp =3D "works"
myProp # =3D> "local"
self.myProp # =3D> "works"


Whereas, I'd expect:
myProp =3D "hello"
myProp # =3D> "hello"
self.myProp # =3D> "hello"


Shouldn't the interpreter try to call the 'myProp' function before going
and creating a new 'myProp' local variable?

-Greg


CONFIDENTIALITY NOTICE

This message and any included attachments
are from Cerner Corporation and are intended
only for the addressee. The information
contained in this message is confidential and
may constitute inside or non-public information
under international, federal, or state
securities laws. Unauthorized forwarding,
printing, copying, distribution, or use of such
information is strictly prohibited and may be
unlawful. If you are not the addressee, please
promptly delete this message and notify the
sender of the delivery error by e-mail or you
may call Cerner's corporate offices in Kansas
City, Missouri, U.S.A at (+1) (816)221-1024.
---------------------------------------- --
------_=_NextPart_001_01C479A4.87C345E3--
 
G

Gennady

Fitzgerald said:
Is this a bug?

No, it is not (see bellow).
def myProp= (var)
@var = var
end

def myProp
@var
end

myProp = "local"

This will always be interpreted as the variable assignment to avoid
inconsistency. Just imagine the case when you have such a statement
where you do mean assignment to a local variable 'myProp' (storing
intermediate results of some computation) and later on you add a method
myProp=(value).

Gennady.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top