Ruby Study Notes 1: Ruby Study Notes

Source: Internet
Author: User
Tags ojs

Ruby Study Notes 1: Ruby Study Notes


Ruby returns the last value in the method by default.
To return multiple values, you can use an array.
You can return a value by forcibly declaring return.
The basic output method is to use puts (output line) and print (print directly ).
The Basic Input Method is gets (read a row that contains '\ n' at the end of the row, which can be eliminated by chomp ).
The pure phenomenon object language is also a dynamic language (although it is not used today), so it is honestly object-oriented.
There are two simple and crude methods to store multiple elements. Array [] and hash table {}, and there are various functions.
Strongly recommended beginner Online Learning Website:, it's so good!
Various codes

Eg1: Create a hash table

ojs = {}ojs["poj"] = :Aojs["hdu"] = :Aojs["uva"] = :Bojs["zoj"] = :Bojs["CF"] = :Sojs["TC"] = :Sratings = { |rate| ratings[rate] += 1 } print ratings puts "" puts "===============================" print ojs puts "" puts "===============================" 3.times {print "hey!"} puts "" puts "==============================="  print ojs.length puts "" print ojs.keys puts "" print ojs.values puts "" ojs.keys.each { |name| print name; print " "; print ojs[name]; puts ""; } puts "===============================" print"x.txt") puts "===============================""x.txt", "a") do |f|   f << "HACKED!\n"   end print"x.txt") puts "===============================" print File.mtime("x.txt") puts "" print File.mtime("x.txt").hour puts "" puts "==============================="

Eg2: Create a hash table for reading data from a file

# Read the database of a File and output def load_oj (path) ojs ={} File. foreach (path) do | line | name, value = line. split (':') ojs [name] = value end print_oj (ojs) enddef print_oj (data) puts "================================" print "name \ tvalue \ n "data. keys. each do | name | puts "# {name} \ t # {data [name]}" end puts "============== ==================== "endoj = load_oj (" x.txt ")

Eg3: read student information from the file and Output

# Read Student information from the file and output class Student # attr_accessor: name # attr_accessor: numberdef initialize (name = "Unknown", number = "2012309999 ") @ name = name @ number = numberenddef printputs "# {@ name} \ t # {@ number}" endenddef load_stu (path) data ={} File. foreach (path) do | line | na, no = line. split ('') s = Student. new (no, na) data [s] = 1 enddataenddef print_stu (data) puts "================================" print "name \ tnumber \ n "data. keys. each do | stu. printendputs "==============================" enddata = load_stu (" y.txt ") print_stu (data)

Eg4: enter four integers in a row to calculate the maximum number of public approx.

# Input four integers in a row to calculate the maximum common approx. def gcd (a, B) if B = 0 return a else return gcd (B, a % B) endendstr = gets. chompa, B, c, d = str. split ("") g1 = gcd (. to_ I, B. to_ I); g2 = gcd (c. to_ I, d. to_ I); g3 = gcd (g1, g2) puts "gcd (# {a}, # {B}, # {c}, # {d }) = #{g3 }"

For Study Notes

How to write Chinese notes

How to write Chinese notes

As the saying goes, "It's better to remember with ink", and "it's better to write your mind over a thousand times ". The teacher makes the class clearer in class. If the students do not remember it, they will forget it later. Note-taking is an extension of memory for future review and searching. The more advanced the learning, the more important it is to remember. Students take notes while attending lectures in the classroom. They can be in the best learning status of brainstorming, hands-on, and ears. They can suppress the "thoughts" and make their attention highly concentrated, improve efficiency, and deepen their impressions. Note Taking can also speed up writing and save time. Teachers should teach students to take Chinese notes from the upper grades of primary school. When I was a child, students learned to take Chinese notes, which laid the foundation for future Chinese learning and other subjects, formed self-learning ability, and formed good study habits, and can be used for life.

How do I take Chinese notes? Students should write their preview notes, class notes, and some Chinese homework together in one book, collectively referred to as "Chinese notes ". In this way, the complexity can be simplified, which not only reduces the Learning Burden of students, but also reduces the burden of teachers' correction. There are both checks on students' previewing, feedback on classroom teaching, and acceptance of basic knowledge. The teacher can correct the Chinese notes and receive the effect of "three in one fell swoop.

It is best to use a 16-open "course preparation notebook" in a Chinese notebook. Draw two straight lines on both sides of each page and divide them into three parts. One copy on the left is about two characters in width, which is used for project recording and serves as a Directory Index. the other copy on the right is about one inch in width and is used for remarks. This part is used flexibly by students, note some difficult questions, your own comments, feelings, and learning methods. The content of this part is inconsistent. the widest and most important one in the middle is, the learning content is recorded in this section.

After the preparation is complete, the next step is how to remember. You can take Chinese notes in three stages:

1. Preparations before class

Before learning a new course, students should preview the course, and record the content learned in the course and the problems they cannot solve in the middle and right parts of the Chinese notes respectively. The words and words that can be solved through the tool book are all completed at this time, which is one of the three parts of the Chinese notes.

2. Lecture Notes

This is the most important part in Chinese notes. In a Chinese class, students need to take notes while taking lectures, record the content of the new course in the middle column, and record the content that can be corrected due to inaccurate understanding in the preview in the remarks column on the right. At this time, there are two points to note: first, students can't talk about it. After the course, the students write the content they want to remember on the blackboard; second, the students cannot write down all the words the teacher says. On the basis of understanding, they should listen and think, sum up the key points, and generalize them into key sentences or words, then write it to the Chinese notes, as long as the meaning is correct. When starting the training, the teacher should say slowly what needs to be recorded, and repeat the long sentences and important points one or two times. Keywords, new words, Homophone Words, and easy-to-mix and easy-to-error words to be remembered. Teachers should blackboard writing to prevent students' mistakes.

3. consolidation after class

After a Chinese lesson, students need to take notes. The questions that have been solved in the text should be followed up, and the missing parts should be supplemented. It is best to remember them in summary, the good words and good sentences in the article can also be excerpted based on interest. After the course is organized and modified, the students' understanding of the content is deepened and their understanding is improved. The content to be recorded after class also includes some exercise questions after the course, such as the words to be copied, the words to be interpreted, the words to be interpreted, the meanings of the key sentences to be understood, and the brackets, sentences. In this way, the content of each lesson is concentrated on the Chinese notes, so that the knowledge can be easily classified for review and search; students can save the additional effort to write their homework, and the Chinese notes can be handed over as homework; when correcting Chinese notes, the teacher not only accepted the basic knowledge of the course, but also checked the students' preview and lectures. During the training process, teachers should focus on students, solicit Students' Opinions, constantly improve their practices, and do not insist on consistency in form and content. This can cultivate students' creative and divergent thinking abilities.

Chinese classroom learning and guiding strategies

How to take study notes?

Copy the wrong question and repeat it with your own memories.

Related Article

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