difference between ', " and :

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.

eddie wrote:

I've taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby I'm going immediately to study it... :slight_smile:

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.

<and so on...>

eddie wrote:

thanks :slight_smile: I've taken this: http://www.sapphiresteel.com/The-Little-Book-Of-Ruby I'm going immediately to study it... :slight_smile:

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

   http://www.ruby-doc.org/

along with a lot of other documentation.

Learn to use irb to try examples interactively.

regards

   Justin

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