# When to use : before variables?

**URL:** <https://www.ruby-forum.com/t/when-to-use-before-variables/49442>\
**Category:** Ruby\
**Created:** [December 4, 2005, 6:50pm UTC](https://www.ruby-forum.com/t/when-to-use-before-variables/49442 "2005-12-04T18:50:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [December 4, 2005, 6:50pm UTC](https://www.ruby-forum.com/t/when-to-use-before-variables/49442/1 "2005-12-04T18:50:21Z")

</div>

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 =\> 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.

---

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [December 4, 2005, 6:54pm UTC](https://www.ruby-forum.com/t/when-to-use-before-variables/49442/2 "2005-12-04T18:54:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [December 4, 2005, 7:06pm UTC](https://www.ruby-forum.com/t/when-to-use-before-variables/49442/3 "2005-12-04T19:06:35Z")

</div>

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 !=  
:bar but :foobar == :foobar. It is a space and time saver to use  
symbols as  
constants, keys etc. rather than using a string constant.

More on Pg. 308 of Pickaxe 2nd edition.

---

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [December 4, 2005, 8:03pm UTC](https://www.ruby-forum.com/t/when-to-use-before-variables/49442/4 "2005-12-04T20:03:37Z")

</div>

Hi Mark,

Mark E. wrote:

> More on Pg. 308 of Pickaxe 2nd edition.

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

g,
