Using Ruby Symbols -
For the first time, I tried to learn Ruby two years ago, now I have started again. Because of which I stopped, because I could not understand the symbol class. And now I am at the same point again, when and when you use symbols, I have read other posts on Googled for many explanations, along with stack overflow, but I am still unable to understand it yet.
At first I thought that there was a way to make the symbols "continuously named", without going through the same process without java.
An arbitrary value However, when you use it in an example, it does not mean too much In short, symbols are light strings, but they are also irreversible and non -Rembers are collectible. You should use not as an irreversible string in your data processing tasks (remember, after the symbol is made, it can not be deleted). You usually use symbols for naming. # Special access cases # access hash value user = user.fid (param [: id]) # name some attr_accessor: first_name # opts set hash value parameter db.collection.update ( Query, update, multi: true, upset: true) Let's take the first example, If you have a simple word string that is often seen in your code and you do not do anything excite (interpolation, GSUB, upcase, etc.) If so, this is probably a good candidate symbol. However, is it only Is applicable for the actual application that is used in the form of nomenclature such as naming, but not actually the text, but actually when the program is running ... like text from user / web etc? < / Blockquote> I can not think of a single case, where I want to change the symbol from the user / web (except for parsing the command line options) primarily due to the results (once created) In addition, many editors have provided different colors for symbols to highlight them in the code. Take a look at this example public static final string ALL = 8;
attr_accessor: first_name etc. Are the symbols just a light string class? I am having trouble understanding that I should explain how, how and how the symbols should be used in my own sections and frameworks.
Paramus [: ID] . There may be hundreds / thousands scattered around the codebase in a nominal large rail app. If we reach that value with that string, then
parameter ["id"] , it means that every time the new string allocation (and that string needs to be collected later). In the case of symbols, it is actually the same symbol everywhere memory allocation, less work for garbage collector and even you (
:
"< / Code> is faster to type)
Comments
Post a Comment