Like many programming languages, Ruby also provides a complete data structure to store and manage the objects. Arrays are created using square brackets and a single object reference list separated by commas.
presidents=["John", "Richard", "Gerald",
We all know that you need to use the Configure--disable-pthread parameter when compiling ruby. Yes, configure--disable-pthread allows you to get about 30% performance improvements. But, what is this for?
All of this we need to use the Strace tool,
Often we need to store and get data in a more transparent way. The Marshal module provides a simple object persistence, and the Pstore library is built on this technology. The DBM Library is used as a hash and is permanently stored on disk.
1
1 send a message to an object
When you call a method, you send a message to an object, and in Ruby we can decide which method is invoked at runtime. This is what the Send method does, and he accepts a symbol as an argument.
For a simple example,
1 open and close a file
Class method File.new opens a file and instantiates it as a file object, and his first argument is the filename.
The optional second argument is called the mode string (which is also derived from c). He means to open a file
A real variable starts at the @, its scope is limited to the self object. Two different objects, even if they belong to the same class, can have real variables of different values. From outside the object, the real variable cannot be changed or even
In this chapter we will discuss more Ruby process control.
Case
We use case statements to test for ordered conditions. As we have seen, this is quite close to the switch of C,java, but more powerful.
ruby> i=8
ruby> case I
| at 1, 2..5
| print "1
Recently because to do a class, so yesterday installed a Windows, feel free to do nothing, want to install a Ruby play.
Official Rubygems source Because some resources are placed on the Amazon S3, so sometimes the ventilation, in Linux I use
The use of simple methods
There is a list of strings that need to be converted to uppercase for each of these strings, and we can do it in a simple notation.
Copy Code code as follows:
Name_list = ["Chareice", "Angel"]
In ActiveRecord, you can define the association between model in a convenient declarative way, for example:
Copy Code code as follows:
Class Topic Has_many:p OSTs
Belongs_to:user
End
Has_many and belongs_to are actually
1. String Object definition
The definition of a string object can use "and", for simple strings, it is recommended to use ' to define, ' the difference between efficiency and ' high, ' and ' is that ' the string defined in ' is the final form, even
If you want to see the source code for the ActiveRecord update_attribute function, a more common approach is to search for Def Update_attribute directly from the Rails source. Blog The Pragmatic Studio introduces a more convenient technique to
1. Use Ruby Eventmachine and Em-http-server gem to complete a simple httpserver to provide file download functionality
2. Using the Filestreamer of EM to send the file asynchronously, the header is assembled before the file is sent, and then the
P and puts are the most commonly used methods in Ruby, and many children's shoes may think they are similar and are not noticed when they are used, but they are obviously different when they are carefully studied.
Let me give you an example.
It is early to know that Ruby has 4 methods of equality, namely: "= =", "= =", "Equal?" and "Eql?", the usual procedures are used, but feel a lack of in-depth understanding of it, reading the rails part of the source code when you can not grasp the
Beginners Ruby, many need to learn, now start to try to write a script using Ruby, which uses a lot of file-related operations, here to organize some. Easy to find again later.
Whether a file or directory exists
Copy Code code as follows:
In Ruby we want to implement the method of traversing the specified directory, the online method is also very much, we can refer to reference, such as the traverse.rb file below the contents of:
Copy Code code as follows:
Because Windows file deletion mechanism is different from Unix like, so does not guarantee that the following code can be used in Windows, which child upper I test in Windows also good AH!
Copy Code code as follows:
#!/usr/bin/ruby
First, the preface
IronRuby is a ruby implementation in. NET, and ruby.net this Open-source project, the main difference is that IronRuby leverages Microsoft's newest DLR, while Ruby.net is fully leveraging the original CLR implementations.
In Word2013 documents, users can add Hanyu Pinyin to Chinese characters with the help of the phonetic Guide feature. In general, Pinyin is added to the top of the Chinese character. Since Chinese characters and Pinyin are merged into one line, the
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.