When to use : before variables?

  • Thread starter Daniel Völkerts
  • Start date
D

Daniel Völkerts

Hi out there,

after looking at rails and the pickaxe book (not totally red yet, just=20
used as a reference) I still wondering when to use just a construct

:a =3D> something

What does it stands for and when to use it? Please apologize if it's a=20
basic questions, but I can't realize myself the usage.

If someone has a page no. in the pickaxe book, I'm glad to read the=20
chapter ;)

Thanks in advance.
--=20
Daniel V=F6lkerts
Protected by Anti Pesto.
 
R

Ryan Leavengood

Look up Symbols. The colon :)) is used to create them.

The basic idea is that if you are using a String as the key or value
for a hash in many places, it is more efficient to use a Symbol.

Ryan
 
M

Mark Ericson

------=_Part_18171_25829422.1133719527632
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It helps not to think of :a as a variable (you won't see it on
left-hand-side). It is an identifier called a 'symbol' or in some other
languages an 'atom' or 'interning.' A symbol is guranteed to be the same
(for the same string) everywhere it is used. Atoms can be introduced ad-hoc
in your code and anywhere you use the same atom is assured to match :foo !=
=3D
:bar but :foobar =3D=3D :foobar. It is a space and time saver to use symbo=
ls as
constants, keys etc. rather than using a string constant.

More on Pg. 308 of Pickaxe 2nd edition.

<Mark/>

Hi out there,

after looking at rails and the pickaxe book (not totally red yet, just
used as a reference) I still wondering when to use just a construct

:a =3D> something

What does it stands for and when to use it? Please apologize if it's a
basic questions, but I can't realize myself the usage.

If someone has a page no. in the pickaxe book, I'm glad to read the
chapter ;)

Thanks in advance.

------=_Part_18171_25829422.1133719527632--
 
D

Daniel Völkerts

Hi Mark,

Mark said:
More on Pg. 308 of Pickaxe 2nd edition.

Thanks a lot. That are these kind of programming constructs I've to=20
learn. I'll read the pages.

g,
--=20
Daniel V=F6lkerts
Protected by Anti Pesto.
 

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
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top