Simplified Chinese (learning and reading Source): http://blog.itpub.net/11379785/viewspace-1199963/
Http://ruby.learncodethehardway.org/book/
Traditional edition: http://lrthw.github.io/
Code:
1 puts "Hello World!"2 puts "Hello Again"3 puts "I like typing this."4 puts "This is fun."5 puts ‘Yay!Printing.‘6 puts "I‘d much rather you ‘not‘."7 puts ‘I "said" do not touch this.‘
It was edited in the sublime editor.
Discovery (it is the feature of the edge editor of sublime ):
When double quotation marks or single quotation marks are entered, an excellent editor will appear in pairs. However, when you enter the content in single or double quotation marks, you enter one quotation mark instead of the other. That is:If the content is output by string, it is also input by normal text.
The following is a copy error message, because there was no error at the beginning and only a copy error was returned:
If you see an error message similar to the following:
ruby ex1.rbex1.rb:4: syntax error, unexpected tCONSTANT, expecting $endputs "This is fun." ^
It is very important for you to understand this content. Because you will make similar mistakes in the future. Even now, I will make such a mistake. Let's look at it in a row.
- First, enter the command in terminal to execute the ex1.rb script.
- Ruby tells us that there is an error in row 4th of the ex1.rb file.
- Then the content of this line is printed.
- Then Ruby outputs a ^ (insert symbol, caret) symbol to indicate the wrong position.
- Finally, it prints a line of "syntaxerror" to tell you what kind of error happened. These error messages are usually very difficult to understand, but you can copy the error information to the search engine, and then you can see that others have encountered the same error, and you may be able to figure out how to solve this problem.
Note:'#' Has many English names, such as octothorpe, pound, and hash) "," mesh (network )」.
Subsequent problems:
- Let your script output another line.
- Let your script output only one line.
- Place a # (octothorpe) symbol at the beginning of a line. What is its role? Study for yourself.
- From now on, unless in special cases, I will no longer explain how each exercise works.
- How to connect two strings for output, such as "she said" and "No way! 'Connect, do not use the stupid "+" connection.
Suggestion: do not make things small
Feeling: no feeling.
Lrthw Note 2