Instance Variable

B

BlueHandTalking

If you have a class 'Thing'

does name of instance variable have to be:

@thing = Thing.new

or is

@widget = Thing.new

O.k. to use?

jet
 
S

Steve Klabnik

[Note: parts of this message were removed to make it a legal post.]

Variables can be named whatever you'd like. Feel free to use

@widget = Thing.new

If you feel that 'widget' is a good name.
 
I

Iñaki Baz Castillo

El Martes, 12 de Enero de 2010, BlueHandTalking escribi=F3:
If you have a class 'Thing'
=20
does name of instance variable have to be:
=20
@thing =3D Thing.new
=20
or is
=20
@widget =3D Thing.new
=20
O.k. to use?


local_aaa =3D Thing.new
CONSTANT_BBB =3D Thing.new
$global_ccc =3D Thing.new
_a_n_y_ =3D Thing.new
@attribute_1 =3D Thing.new
@@class_var2 =3D Thing.new


*any* is valid, so any kind of attribute name is also valid.

Again I think you ask this because Rails conventions. If so remember please=
=20
that this is a Ruby maillist, and Rails rules/conventions are not a must he=
re.



=2D-=20
I=F1aki Baz Castillo <[email protected]>
 
B

BlueHandTalking

Inaki,

Thanks for the example list.

Actually, I did not ask because it is a Rails thing.

I asked because I needed some fundamental, like very
basic knowledge about Ruby that I did not understand.

....and I did RTFM before this post.

Thanks again,

Jet
 
S

Seebs

If you have a class 'Thing'

does name of instance variable have to be:

@thing = Thing.new

or is

@widget = Thing.new

O.k. to use?

How far do you think you'd get if you could only use "@fixnum" for numeric
values used as instance variables?

For that matter, what name would you give to an instance variable that
might, like any other variable in the language, hold different types of
objects in different contexts?

In short, the name is purely up to you.

-s
 

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

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top