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