ruby on rails syntax- when does : come before v. after the variable? -
Perhaps obvious; I am very new to rail.
My question: Is there a rule or a simple way of remembering when a colon comes before or after a variable? An example of what I'm talking about with my I with Is there a way to remember when the colon arrives at the end, and when it comes in the beginning, or is it something that you miss on a variable-to-variable basis? Besides, why have both been found here in a row? I really want to understand this :) Thanks! There is no real benefit other than the feature and less typing. If you need to continue supporting Ruby 1.8, then logic can be argued. You should continue to use the old syntax. You must feel in the example provided This is a method that passed single variable It is being done, which is going to be a hash. So are the following. As I have made progress in the line notice, this is a bit more typing, but they are all doing the same thing. Each passes through protection_from_forgery with the same key / price combination. Going back to your original question of left vs right, just keep in mind that on the left is your key and this symbol is The following examples are all valid hashes. Foo = {time: "baz"} foo = {time: 1} foo = {time :: baz} foo = {bar: some_object} < p> Then it is being felt that it is a shortcut for the symbol key to something, symbol, number, string, object, etc. ... it can change the old syntax {: bar = & gt; Some_thing} If your key is something other than a symbol then you will need to use the old syntax. application_controller .
with protection_from_forgery :: exception
: v. the
: exceptions .
with: exception: syntax is only for
: Together = & gt; : Exception
protect_from_forgery:
foo = {1 = & gt; : Bar} foo = {"string" = & gt; Some_object}
Comments
Post a Comment