1. Send email via SMTP
Every week Holden Glova,pat Eyler, and Phil Thomson submits a Ruby http://www.rubygarden.org/News (Weekly) article to the Ruby Garden website (rwn). A Ruby script receives this article via email, converts it from the original
Martin Fowler: Of course (willing to spend half the time to write unit tests)! Because unit testing enables you to get your work done faster. Countless practices have proved this. The more stressful your time is, the more you have to write unit
In many cases, when you design your application, you may want to implement a method that is used only for internal use by one object and not for other objects. Ruby provides three keywords to restrict access to methods.
Private: A method that can
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,
1 Understanding Allocate
In some special environments, you may want to create an object without invoking its constructor (i.e., initialize). That is, you want to create an empty object. For example, suppose you have an object whose state is
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
Ruby Regular Expression
Three methods of representation:
Regexp.new (' ^s*[a-z] ')
/^s*[a-z]/
%r ... {^s*[a-z]}
Test code:
Def show_reqexp (A, re)
if a =~ re
"#{$ '} > #{$ '} '
else
' no match "End end
puts Show_reqexp" ("Fats Waller",/ll/)
We often deal with code like this:
Name=person?person.name:nil
Take a property of an object, first determine whether the object is nil, not nil return the object property, otherwise return nil. This kind of code is more disgusting, is there a more
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
1, Ruby in the method name and variable name rules ( beginning with lowercase letters, the separation between words using "_",), but you can take the method name behind! (blockbuster method) or? (A Boolean type returns a value).
2, the method of
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
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
Reading a record includes specifying those specific data that you are interested in, you specify criteria for the active record, and the active record returns you some objects that contain data that matches the criteria.
The easiest way to retrieve
This time we continue to test controller, or Store_controller.
1. Test the checkout function first to add code to STORE_CONTROLLER_TEST.RB:
def test_checkout
Test_add_to_cart
get:checkout
assert_response:success
Assert_not_nil assigns ( :
The previous essays are written in accordance with the examples in the book, but, this time in the test model, according to the example of the book How the code can not go, so on the other way, this becomes a question.
According to the book, at the
Relevance Consulting's Stuart Halloway recently wrote a series of blog posts about the "Ruby vs. Java Geek talk". The inspiration for this series comes from his recent experience with a zero-start, previously constrained Ruby project that has been
In an MVC based Web application, the application logic and the access to the data are accomplished by C, the controller, in MVC. Therefore, a deep understanding of the controller provided by the MVC framework is essential for developing an efficient,
Early in the morning, your leader rushed over to find you: "Quick, quick, urgent task!" Recently ChinaJoy is about to start, and the boss asks for an intuitive way to see the number of people on the line in each of our new online games. ”
You
Today you come to work as usual and start your programming work as always.
The project manager tells you that today you want to add a new feature to the server, and you want to write a method that handles the book object, wrapping all the fields of
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