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 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
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
Ruby handles strings like numbers. We enclose them in single quotes (' ... ') or double quotes ("...").
Ruby> "abc"
"abc"
ruby> ' abc '
"abc"
Single and double quotes have different effects in some cases. A string enclosed in double quotes
A local variable starts with a lowercase letter or an underscore (_). Local variables do not contain nil values like global and real variables before initialization.
ruby> $foo
Nil
ruby> @foo
nil
ruby> foo
ERR: (eval): 1:undefined local variable
The Fruit class in the previous section has two real variables, describe the type and state of the fruit. Until a custom inspect method is written for this class, we understand that it does not make a reasonable explanation for a fruit that lacks
Standard type for Ruby:
A. Number
Class Test
3.times {print "X"}
1.upto (5) {|i| Print I, ""}
99.downto {|i| Print I, ""}
50.step (80,5) {|i| Print I, "" "" ""
a = ""
B = "
puts" "
puts A + b
puts integer (a) + integer (b)
end
Output:
1. Read-write properties of member variables: Attr_reader and Attr_writer class Test
Def initialize (name)
@name = name
end
attr_reader:name
attr_writer:name end
test = Test.new ("AAA")
puts test.name
test.name = "BBB"
puts Test.name
If
The string in the Ruby language is mutable, unlike a string in Java, C #, which is immutable. Like what
str1= "abc"
str2= "abc"
In Java, for literal strings, a table is maintained inside the JVM, so if in Java, str1 and str2 are the same string
How is polymorphism defined in Java?
I understand this:
Polymorphism needs to be implemented by means of interfaces, that is, all classes that implement this particular interface are like him.
What is duck type?
This is defined in programming
Can ruby write a servlet? Yes, it's not funny, and it's handy, because Ruby's standard library brings a webrick,webrick itself and a Serlvet container, and it's convenient to start a Web server anytime, anywhere.
First look at the simplest example,
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.print does not automatically wrap, puts will automatically wrap, one line is not enough to write, you can add "\" to connect
Ruby Code
puts 6/2 print 6/1 puts 'hello world' puts '我们都是'\ '中国人'
Run Result:
Ruby Code
3 6hello world 我们都是中国人
2.==,
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
As you may have noticed, in our previous code, the database definition uses an integer field ID as the primary key, which is a convention for the active record.
Perhaps you should ask, why not use the order number or a meaningful column as the
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
Now our shopping cart program provides two kinds of users with service, one is ordinary users, the other is administrator. The two types of users have different functions respectively. Last time we implemented the function of adding users, this time
In the last content, we wrote the checkout processing. This time we will show the cart and order on a page so that users can easily see their shopping when they place an order.
1. Modify the checkout.rhtml file, just add a code:
"Display_cart")%
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.