First, install Ruby under Linux
1-First, we want to get the latest Ruby release version (currently ruby-1.8.2.tar.gz).
Please download it to www.ruby-lang.org/en/20020102.html.
2-then decompression: TAR-ZXF ruby-1.8.2.tar.gz
3-Last Run:
I do not know if you have to transfer data to the migration file experience, I believe that both the veteran and novice have done it. In fact, doing this is not going to work, but this practice will slowly introduce you to some unnecessary problems.
A running program often encounters unexpected problems. A file to read does not exist; When you want to save some data, the disk is full; The user may enter inappropriate data.
ruby> file = open ("Some_file")
ERR: (eval): 1:in ' open ': No such
The iterator was not invented by Ruby. It is widely used in all kinds of object-oriented languages. In Lisp, it's just not called that. However, the concept of iterators is not familiar to many people, so we will do a more detailed description here.
You create an array by listing the elements in square brackets and separating them from each other by commas. The array of Ruby can accommodate different object types
ruby> ary = [1, 2, "3"]
[1, 2, "3"]
Just like the string mentioned earlier.
A string object in Ruby holds and manipulates one or more bytes of any sequence, usually representing the character representation of the human language.
Simple string literals are enclosed in single quotes (single quote characters). String value
One, string operation
string interpolation
1.#{}: Any legitimate Ruby code placed in #{} will be evaluated and replaced with an evaluation result inserted in the original location
2. Single and double quotation marks differ:
Double quotes allow
If you test the RESTful service by hand, it will be very tedious. Of course, there are some browser plug-ins that can help you manually test by using a visual interface, such as postman, rest console, but every time a system version is updated, you
Let's briefly describe a unique feature of Ruby. block, a piece of code that can be associated with a method call, almost as if it were a parameter. This is an incredibly powerful feature.
You can use the block implementation callback (but it is
Focus on private and protected
Public
The default is public, the global can be accessed, this does not explain
Private
C + +, "private" means "private to this class", but Ruby is the "private to this instance".In C + +, for Class A, you can
Ruby in the implementation of Web crawl, the general use is mechanize, very simple to use.
Installation
Copy Code code as follows:
sudo gem install mechanize
Crawl Web pages
Copy Code code as follows:
Require '
Recently I got a lot of pictures from the designer, the results are 1.png,2.png such file name, they also need to make these files into a readable file name, do not want one to be modified, so wrote a simple script to achieve a lot of multiple files
Rails built log functionality, or more precisely, rails exposes the Logger object, which can be used in all rails programs.
Logger is a simple log frame ported from Ruby (you can type RI logger to view the documentation of the standard library in
Active support is a set of libraries provided with rails, active support extends some of the classes in Ruby, and this time we'll look at some of the most common features.
1. Extension of the number type
The Fixnum class adds two methods: even and
In the last content, we realized the format of emptying the shopping cart and the amount. The module that implements the order this time.
1. First, we create the order table in the database, and create the SQL of the table as follows:
CREATE
In the previous section, we demonstrated how to build a list of items, and this time we built a simple shopping cart based on the previous content.
1. First we want to create a table that holds customer shopping information:
Database scripts:
Rails supports three of relationships between tables, one-to-one, One-to-many, Many-to-many, and you need to include a declaration in model to identify these associations: Has_one,has_many,belongs_to,has_and_belongs_to_many.
A one-to-one
Demandfunction, you need to pass a string through a parameter to do a regular match' [0-9]+ ' def func (str, reg) Str.scan (reg) EndSince Reg is defined elsewhere, Reg is a string, which is found to be unable to be used directly for regular
Four comparison functions in Ruby (equal ?, Eql ?, ==,==) For details, rubyeql
There are four comparison methods in Ruby: equal ?, Eql ?, ==,==, And the performance in different classes is very different. It is also easy to get confused when using
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