Based on the current knowledge of Ruby and the help of Ruby Standard library, you should be able to build a real-world application.
In the beginning, I provided a sample application that used a lot of the Ruby features we had discussed. This
1 RSS Standard Library
RSS is xml-based, so you can simply parse it as an XML. But, in fact, he has a higher level of proprietary parsers to parse him out. The standard of RSS is also very confusing.
He has a lot of inconvenience, is the standard
1 storing the code like an object
When you want to store a piece of code in the form of an object, Ruby gives you several methods. Here we'll introduce the Proc object, the method object, and the Unboundmethod object.
The built-in proc class wraps
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 detect whether the file exists and its size
Filetest's exist? Method can detect whether a file exists:
Flag = filetest::exist? ("Lochnessmonster")
Flag = filetest::exists? ("UFO")
# exists? is a synonym for exist?
If we want to know if the
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.
We always want to classify unknown events. When it happens, passing a piece of code as a parameter to other methods is the easiest way to do it, which means we want to work with the code like we do with the data.
A new process object can be created
Method_missing is a common technique for Ruby metaprogramming (metaprogramming). The basic idea is to invoke a method that does not exist by implementing a callback. A typical example is the dynamic lookup of a ActiveRecord (the Dynamics Finder).
Algorithm class operations, using the partition method, merge sort.
#encoding: Utf-8 #author: Xu Jin, 4100213 #date: Oct #MergeSort #to sort an array by using MergeSort algorithm # Example output: #The original Array is:[4,-----------------, 4,
For example, consider the following regular expression for the matching date:
Copy Code code as follows:
/\a ((?: 19|20) [0-9]{2}) [\-\/.] (0[1-9]|1[012]) [\- \/.] (0[1-9]| [12] [0-9]|3[01]) \z/
With the RE, regular expressions can
This chapter deals with some practical issues.
Statement delimiter
Some languages require a certain type of punctuation, typically a semicolon (;) to end each statement of the program. Ruby uses the shell's SH and csh convenience. Multiple
We may need to clean up when a method is finished. Perhaps an open file needs to be closed, the buffer data should be emptied, and so on. If there is always a single exit point for each method, we can safely place our cleanup code in a location and
Like Ruby Metaprogramming, puppet and chef use a lot of Ruby's language features to define a new deployment language.Share a few in the actual project used in the scene, limited capacity, if there is a better program, please leave a message to me:
Recently, a lot of people with rails to develop micro-trust project friends on the GitHub began to use Weixin_rails_middleware, weixin_authorize, but also many talked about Ratchet, Spring Festival began to now, has been doing micro-letter
Under Windows, we all know where the hosts file is, but in the Ubuntu system, there are other systems, such as the Android phone, and maybe there aren't as many small software that you can easily modify, so let's write it ourselves.
Ruby, which absorbs Perl's regular expressions and Python's readability, is a very human and flexible way to count values, which can be illustrated here:First , print 7 times "Hello,world", as follows:
Copy Code code as follows:
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"]
Recently, there is a need to use a string as a class, for example:
There is a string "Chinamag" that invokes the method under the class Chinamag according to this string.
Solution:
1.rails You can use the Constantize method.
Copy Code code
Begin and end are keywords for Ruby, but there is also an instance method with the name begin and end in range. Now the question is: How do you create their alias method?
If it doesn't work with class Range;alias begin_x begin end, Ruby thinks the
This article discusses one of the basic services provided in ROR: Action view. Action views enable you to present data more quickly to the user. The services for some action views are described in this article, and an example is given to illustrate
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