# Difference between ', " and :

**URL:** <https://www.ruby-forum.com/t/difference-between-and/80535>\
**Category:** Rails\
**Created:** [December 28, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535 "2006-12-28T15:12:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/1 "2006-12-28T15:12:31Z")

</div>

Hi, I’ve seen source like: params[:user] and params[‘user’], or also  
:action =\> ‘new’ and :action =\> :new, is it also possible write  
params[“user”]?  
So, which are the differences between ', " and : ? when use for example  
: instead of others?  
I’ve read that, for example, in a put(‘name: #{user.name}’) the output  
will be name: #{user.name} and with “” instead of ‘’ will be, for  
example, name: John  
is it right?  
can anyone explain me these differences?  
thanks 🙂

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/2 "2006-12-28T16:36:55Z")

</div>

thanks 🙂  
I’ve taken this: [http://www.sapphiresteel.com/The-Little-Book-Of-Ruby](http://www.sapphiresteel.com/The-Little-Book-Of-Ruby)  
I’m going immediately to study it… 🙂

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 4:28pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/3 "2006-12-28T16:28:16Z")

</div>

eddie wrote:

> Hi, I’ve seen source like: params[:user] and params[‘user’], or also  
> :action =\> ‘new’ and :action =\> :new, is it also possible write  
> params[“user”]?

Please read a book about Ruby itself.

:yo is a symbol, ‘yo’ a string. A hash could contain :yo and ‘yo’ as  
distinct keys. But :‘yo’ and ‘yo’.to\_sym are the same as :yo.

Rails prefers symbols because they are mildly more physically  
efficient, and they are much more cognitively efficient.

> So, which are the differences between ', " and : ? when use for example  
> : instead of others?  
> I’ve read that, for example, in a put(‘name: #{user.name}’) the output  
> will be name: #{user.name} and with “” instead of ‘’ will be, for  
> example, name: John  
> is it right?

That’s because #{} calls .to\_s, and :yo.to\_s is ‘yo’.

“yo” is also a string, but “” markers can interpret advanced \ escapes  
and #{} marks.

> can anyone explain me these differences?

A book about Ruby may have come with your copy of it. Curl up with  
that for a few hours, and your own code - between the Rails code -  
will improve a lot.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/4 "2006-12-28T17:36:38Z")

</div>

Look on the Ruby mailing list, I asked the same question and got a great  
answer. The Subject was “Symbols vs Strings”

I won’t reproduce it here since this is a Rails list and not a Ruby  
list.

but check it out, and I think it will more than answer your question.

Matt

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/5 "2006-12-28T17:14:30Z")

</div>

eddie wrote:

> I’ve taken this: [http://www.sapphiresteel.com/The-Little-Book-Of-Ruby](http://www.sapphiresteel.com/The-Little-Book-Of-Ruby)  
> I’m going immediately to study it… 🙂

You might also like Why’s Poignant Guide to Ruby.

> Why’s it poignant?

That’s the author’s pen-name; Why.

> But why is his guide poignant.

Yes, I have heard Why’s guide is poignant like that.

> But why is it…

Yep; it’s his book. Why.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 28, 2006, 9:53pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/6 "2006-12-28T21:53:44Z")

</div>

eddie wrote:

> thanks 🙂  
> I’ve taken this: [http://www.sapphiresteel.com/The-Little-Book-Of-Ruby](http://www.sapphiresteel.com/The-Little-Book-Of-Ruby)  
> I’m going immediately to study it… 🙂

That will not take you very far. The first edition of “Programming Ruby”  
is available free, here:

[http://www.ruby-doc.org/](http://www.ruby-doc.org/)

along with a lot of other documentation.

Learn to use irb to try examples interactively.

regards

Justin

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [December 31, 2006, 11:28am UTC](https://www.ruby-forum.com/t/difference-between-and/80535/7 "2006-12-31T11:28:12Z")

</div>

Eddie,

‘user’ != :user, but Rails uses HashWithIndifferentAccess instead of  
standard Hash i many places, so you can use params[:user] or  
params[‘user’]

See:  
[http://api.rubyonrails.org/classes/HashWithIndifferentAccess.html](http://api.rubyonrails.org/classes/HashWithIndifferentAccess.html)  
[http://redcorundum.blogspot.com/2006/07/symbolickeyhash.html](http://redcorundum.blogspot.com/2006/07/symbolickeyhash.html)

> **[FamUndo.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=famundo.com)**
>
> Great domain names provide SEO, branding, and a memorable experience for your users. Get a premium domain today.

Alain

---

<div class="post-metadata">

**Author:** ![eddie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@eddie](https://www.ruby-forum.com/u/eddie)\
**Post date:** [January 3, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/difference-between-and/80535/8 "2007-01-03T14:56:20Z")

</div>

I’d have to add that there’s a lot of new things Ruby’s learned to do  
between the two editions of the Pickaxe [the nickname readers have given  
to  
“Programming Ruby”]. Once you’ve made it through the first edition and  
feel  
like you and Ruby are a good fit you would do well to pick up a hard  
copy of  
the second edition. Everyone’s favorite method, Enumerable#inject, is a  
prime example of what you’re missing out on.

RSL
