Ror beginner's note

Source: Internet
Author: User
Tags uppercase letter ruby on rails
 

Ror is growing at an astonishing rate, especially when we often patronize JavaEye and find that Ror already has a very good foundation in China. Of course, we should try it out.

At present, there is still very little Chinese information about Ror in China. When you look for it online, there will be only Ruby on Rails practices of Eiffel Qiu (hereinafter referred to as Ror practices ), it must be assumed that Ror has made a great success one day, so the author of this article in China must be the originator of Ror in China. After all, Ror is a new transaction. There must be a lot of people like me who can barely look at E-files. Let's assume that we can directly read the large part of documents, it is expected to be very difficult to get started. Therefore, everyone should study E-paper and share their experiences so that progress can be improved quickly. Here we should pay tribute to Eiffel Qiu!

I only use Java. From my perspective, Ror has such a huge influence. A major reason is that it successfully overcomes the bottleneck of J2EE Development: cumbersome, I know that Ror is also because many technical sites in China have invested in the discussion about whether Ror can ban Java, so many titles such as "Java will die?" In this way, all questions are rampant. With this solid foundation, and Ruby's own maturity (Yukihiro Matsumoto started Ruby development in, that is, same as Java ), ruby and Rails are also from the beginning. No matter what the historical burden is, they will certainly have a place in the Web development field in the future. As for how successful Ror can be, I cannot predict it. It is also said that every programmer should master a dynamic language at the same time as a static prediction. I think it is necessary to invest in Ror learning at this time. I personally think that Ror only focuses on Web development and features high-speed development. J2EE development itself is not always efficient. Therefore, I personally think Ror is not a great threat to Java itself, some people think Ror will be correct. NET has a lot of impact, think about the JavaEye upgrade has been removed. NET version, it seems that Microsoft's days are getting worse and worse. Indeed, Ror has the opportunity to seize a very large part of the market share of Web development, so people who eat Java can also consider moving the line of sight in the direction of j2s or Swing, after all, Java is no longer a pure language, but a platform.

Many angry young people have this idea: Ruby is from Japan, and I will not learn it if it is from Japan. In this regard, I can just give up on it. Technology is without borders. It hinders development for the sake of revenge. It must be a short-sighted behavior. I really hope that one day Chinese people will have a Yukihiro Matsumoto, so I will immediately give up Ruby.

After many days of preparation, I finally found a break without working overtime, so I started a strange Ror tour.

I originally wanted to start on Linux, but since I am still unfamiliar with Linux, I continue to learn development on XP, in the future, if time permits, it is necessary to take time to learn about Linux and Unix. If you want to have a good Ror or program, you will not be able to learn Linux/Unix.

According to the rorpractice, download a ruby185-21.exe file and install it. Then, open the console and run gem install rails -- remote. The depressing time has officially started. I don't know what others are like. Anyway, it is very slow to open RubyForge, it is simply unable to open, it is expected that Ruby is too popular, and the site is a little too boring. Then I re-run the gem install rails (with -- include-dependecies), which is always a Timeout error. I can't download the rail installation file directly. This time it's even worse, I couldn't even open the download page. I cried. The third method is to download InstantRails and HOHO. In my opinion, this one-stop solution truly proves the concept that Ror is better than configuration, I am still thinking about how to use this assumption to manually configure it on Linux, so I struggled for a long time before using InstantRails. After all, it was just getting started, it has never been recommended to use a tool that is too self-active.

Using InstantRails is like using Visual Studio, and IR is ready for you to connect to the database. So what are you waiting for? Hurry up and write HelloWorld ^_^. But it is actually not that simple. At least if IR is used, Ruby cannot be used at will. You must use the console provided by IR, or you must enter the % IR_HOME %/rails_app folder to run the Ruby command. I don't know if I have misoperations or understanding errors, because Ruby has been regarded as a system command when I manually install ruby, it is not so convenient to use IR, and the same command results in different working folders are different. For example, if you want to use the rails command to create a new project, you should run rails [project_name] below % IR_HOME % to run normally, the subsequent ruby script/server live script/generate also have the same problem, it took me a long time to complete the Ror practice example. (it took me five hours to install and complete the sample. It may be a little less than T_T ).

Basically, the process of completing the example using IR is as follows:

1. Decompress InstantRails to % IR_HOME % in a folder. All the documents will tell you that the folder name cannot contain spaces, which is already common in java, no matter what file or folder name, try to avoid non-English characters, spaces, etc. It may not be true, but it is obviously asking for trouble.

2. Run % IR_HOME %/InstantRails.exe on the IR console. Apache and MySQLserver are both started.

3. Open the console, enter the % IR_HOME %/rails_apps folder, or press I Button on the IR console, select Rails Application-> Open ruby console windows, and then run the rails MyTest command, create a MyTest project. Wait a moment and you will see a list of create files records in the console. A MyTest folder is added below % IR_HOME %/rails_apps, which includes the Rails skeleton framework.

4. Follow the Ror practice instructions in sequence. This document is really a beginner's tutorial. We are the good news of Cainiao: P, enter the ruby script/generate command under % IR_HOME %/rails_apps/project_name to generate the controller and model files.

After completing this operation, I personally realized the ease of use of Ror, but this process is not so fun for people like me with low talent, just installing an Ror will make my patience almost the same. I sincerely hope that the Ror will be more popular, so RubyForge will be as influential as SourceForge, you can deploy the image server all over the world, so it is much easier to download it: P. After experiencing Ror, I want to start learning the truth. I chose Ruby in a Nutshell as a tutorial for Ruby. in the next day, I will first understand Ruby syntax, then we can continue. Since I have never played with predictions like python and Perl, I just read the syntax of Ruby, but Ruby in Nutshell repeatedly mentions that Ruby syntax is very similar to Perl and Python, clearly hit me :(. Oh, by the way, Ruby is very similar to C ++ and very fond of expressing relationships with many symbols. After reading the Java program, I think Ruby code is like an abstract painting, it seems that familiarity with Ruby syntax is certainly not as fast as familiarity with Java, so easy to understand.

The following is the Ruby syntax. I searched the internet for a long time and did not find a detailed explanation of the Ruby syntax. When I learned Java or C #, I thought it was full of tutorials, documents, and webpages, there are also a variety of examples to help you understand. It can be used in a big way, but Ruby is not that fun, I did not find a circle on the Ruby official website (maybe my search capability is too weak), so I just want to read it from Ruby in Nutshell, so there is no example in my notes. I don't know if I will not understand it myself in a few days :(.

The following sections describe Ruby in Nutshell:

1. Command-Line Options, because we are all Project Oriented, the content will not be checked until I want to use it. Temporarily skipped.

2. Environment Variables, skipped (same as above ).

3. Lexical Conventions: text Conventions, including whitespace, Line Endings, Comments, Indentifiers, and Reserved Words. It seems that there are not many queries with other languages. Different from Java, assume that a + B represents a + B, while a + B represents a (+ B), in this case, is a method call (this is actually a method call method, obviously spaces can no longer be abused), HOHO, I feel Ruby is too casual, I really don't know what a project will look like if Ruby is used in a large-scale pipeline. There is no semicolon at the end as a line break sign. If I want to write a branch, I can use +, -or backslash (I don't know if it means that both the left and right slashes can be used as a hyphen. I will try it later). Haha, it's a bit VB-it's not special; comments start, you can also use = begin... = end to stare at multiple rows (protest against the casual behavior of the little devil again !); There are 40 reserved words. I haven't read the details yet. I don't know many words yet :(.

4. Literials,

A. First of all, it is A number. Ruby is always self-built with full object-oriented nature. Because Ruby's number is also an object compared with Java's full object-oriented nature, java has sent so many versions to the boxing level: P. All the numbers in Ruby are inherited from Fixnum, Bignum, and Float classes, so that all the numbers are class instances and they all have some common methods, such as iteration. A special number is decimal with underline. I don't know what this number can be used for. Is it practical? A indicates 'A'. I think this method is quite good. Others are almost the same as Java, and even support for Bignum.

B. String, two types: "abc" allow substitution and backslash notation; 'ABC' don't allow substitution and allow backslash notation only//And/', Indicating that the double-cited escape string agrees to modify and add a slash to escape the character, but the single-cited escape string does not agree. I think the difference between character escaping is very good, but I don't know what it means to agree to the change. Is it possible that the things produced by a single quote directly become constants? Puzzled ...... There is "abc" efg "in Ruby, and the string is directly written as" abcefg "without knowing how affordable this feature will be in practical applications. There is also support for expressions. Java 5 also provides similar support, but it seems Ruby is more powerful. After all, it is a dynamic language, and anyone is a good guy. The support for this expression is not so clear at the moment. It will not be known until the actual operation. This is used in many examples # $ var #$ {var}, indicating that this is not frequently used. Some special characters are very similar to those in Java. As shown in the following example, they are currently commercially available.

The characters include General delimited strings and here documents. The delimiter is used to display special characters. This part still needs to be explained by others. It seems that it can implement functions such as Dynamic Call methods like JavaScript, and dynamic prediction is good. It is difficult to understand and cost performance as reflection in Java. Here documents to be discussed ......

C. Symbols, A symbol is an object corresponding to an identifier or variable,

: Foo # symbol for 'foo'

: $ Foo # symbol for variable '$ Foo'

There is no practical application. If it is copied as an example, it feels a bit like a HQL variable. The detailed functions should be learned slowly.

D. Array. The Ruby array uses. An array can also be created using modifiers such as % w (foo bar baz), indicating ["foo", "bar", "baz"].

E, Hashes, A hash is a collection of key-value pairs or a collection that is indexed by arbitrary types of objects,This form of key-value pairs is used to represent functions similar to Java HashMap. I don't know if there are so many statements in Java Collection.

A hash expression is a seriesKey => valuePairs between braces.

{Key1 => val1, key2 => val2}
Ruby also has built-in support for the regular expression of the regular table. It seems similar to JavaScript at first, but it seems that there are some more things. This should be studied slowly.
F, Variables, and the variable $ foo in Ruby is a global variable, which is not used by everyone. HOHO. @ Foo, instance variables. I looked at it and explained that I still didn't understand how to use it. The talent is poor ......
@ Foo class variables: similar to Java, class variables that overwrite the parent class generate warnings and must be initialized when class variables are used. Foo, loacl variables, which must start with a lowercase letter or "_". Use range: class, module (This item is also generated), def or do.
A constant starts with an uppercase letter. However, this constant can still be making an assignment again, which generates warnings rather than errors.
Pseudo-Variables: false Variables in Ruby, including self, true, false, nil, _ FILE _, _ LINE _, are specific things and do not agree to use them as Variables.
Value assignment in Ruby can be used for callback.Expr. attr,Assignment to attributes cballsAttr=Method of the resultExpr, you need to try to know the effect.
    
 
Elements

Elements take the following form:

Expr[Arg...]

Assignment to elements callthe[] =Method of the resultExprThis section does not quite understand.

Parallel Assignment,

Target[,Target...] [, *Target] =Expr[,Expr...] [, *Expr]
The method for assigning values to arrays is quite special and can simplify a lot of work. If there are fewer values than the previous ones, then the less is filled by nil.
Short assignments are also supported in Ruby,
Target Op= Expr

This is the abbreviated form:

Target = target op expr
It is similar to the C ++ method, but I am not confused about C ++ :(.

========================================================== ======================================

Finally, the first meeting of Ror was recorded. There are obviously many errors in it. I hope you can correct them and exchange and promote each other. I will continue to add content, especially the Ruby grammar section, which is not complete yet.

Ror beginner's note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.