Ruby two-week Summary

Source: Internet
Author: User

I recently used Ruby to write an automation program. It took two weeks and it was quite convenient. Let's talk about it:

1. Ruby is easy to read the yaml file. during the processing of the. ini file, no database support was found, so I checked the online code and changed it myself.

Ruby is very convenient for reading yaml files. However, to modify one of the yaml files, similar to processing. ini files, you still need to write programs by yourself.

Here is an output statement: P [something]. Note that puts and print. Puts are not printed by default, and press enter is used by print.

By default, if you do not press Enter. P, the something type is printed. For example, the double quotation marks of a string are printed and an array is printed.

For example, when reading yaml files or other types of files, you can print them out with P to see what is being read, which is very useful for debugging.

For example, the yaml file has the following representation:

Buildresults:

-Modes: Release

Path: C:/build/result/release

-Modes: Debug

Path: C:/build/result/debug

-Modes: custom

Path: C:/build/result/custom

The P statement can be used to print the representation to see the structure at that time:

Require 'yaml"

Yaml = yaml. Load (file. Open (....))

Buildresults = yaml ['buildresults']

P buildresults

If you know the data result, you can process it accordingly.

2. I am not familiar with the regular expression, or I will forget it if I have learned it.

When using, I reference a Website: http://www.rubular.com/really saves me a lot of trouble.

By the way, the knowledge points are: the difference between/.../AND/.../I. The previous one is case-sensitive and the latter one is case-insensitive.

3. By the way, I forgot about the IDE. There is no doubt that a good ide can improve work efficiency. I am using Aptana Studio. 3. The general feeling is that

Enough. If you have good open-source products, you can recommend them to your friends.

4. Ruby prompts errors in explanation. For example, if a buddy uses a library function but is eager to use the function, give the namespace before the Function

Forgot. Later, the ruby prompts: <name error>. I was debugging for a while. I checked on the Internet and found that there were quite a few people with such errors.

In addition, when writing automation, we often need to compare the path, such as the string = operation, include? Operation, but be sure to pay attention

The strings on both sides of the operator must be case-insensitive. For example, if a = "C:/goo.txt" B = "C:/goo.txt" is written as a = B or a. Include? ("C:/goo.txt") both

False is returned. A. downcase = B. downcase A. downcase. Include? ("C:/goo.txt ")

 

Just write it down. Some playbooks are unclear. Please forgive me.

 

 

 

 

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