Through the previous lecture, we have some knowledge about the basic framework of rest on rails, but how does it return different types of resource representations Based on the client request type? This is what we want to talk about. The secret lies
The fruit class in the previous section has two real variables, indicating the fruit type and status respectively. it was not until we wrote a customized inspect method for this class that we knew it would not give a reasonable explanation of a
The ruby unless expression runs only when the condition is false.CodeBut it does not understand the logic combination with the condition "& |". Whether it is false or false to run the unless code block, or false | false to continue running.
In fact,
Reference books: Agile web development with rails 4th Edition
Create a new website and create some default directories and files:
$ Rails new
Start the server and run the following command in the project directory:
$ Rails Server
Default
1. First read the object_id of the string.
Str1 = "anleb" str2 = "anleb" puts str1.object _ idputs str2.object _ id
Output:2295250022952490
Different IDs indicate that objects have the same values, but they are different. What is different,
Ruby is...
A dynamic, open source programming language with a focus on simplicity and productifunctionality. It has an elegant syntax that is natural to read and easy to write.
Translate and organize documents of common Ruby libraries, and
This rexml library can be used for parsing XML documents in ruby.
The rexml library is an XML toolkit of Ruby. It is written in pure Ruby and complies with the xml1.0 specification.In ruby1.8 and later versions, the ruby standard library will
From a stranger to a preliminary understanding; from reading to hands-on practice, I want to say, you are very beautiful!
Ruby is a pure object-oriented scripting language developed by yukihiro Matsumoto in Japan. This language is designed to
Local variables start with lowercase letters or underscores (_). Local variables do not include nil values before initialization like global variables and real variables.
Ruby> $ fooNilRuby> @ fooNilRuby> fooErr: (eval): 1: undefined local
Use before_invocation to verify the call permission
API
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Class blogapi Api_method: hello_world,
: Expects => [{"password" = >:string}, {"user" =
As ruby is a pure object-oriented language, everything is an object. methods are objects and classes are objects ..., therefore, self has many environments. Only by distinguishing the meanings of self in different environments can we better
Let's look at a more interesting program. This time we will test whether a string matches the description produced by concise pattern encoding.
In these pattern modes, some characters or character combinations have unique meanings, including:
Copy
Life cycle:
Yukihiro Matsumoto was born on February 1, April 14, 1965 in Tokushima Prefecture, Japan. In 1984, he studied at the Department of Information, the third discipline of zhubo University. Two years later, I will be absent from school and
The real world is full of objects. We can classify them. for example, when a very small child sees a dog, no matter what type it is, they will be called "bow-wow". We are born to have the ability to understand the world by type.In terms of OO
Global variables start with $. They can be accessed anywhere in the program. Before initialization, the global variables have a special value nil.Ruby> $ fooNilRuby> $ foo = 55Ruby> $ foo5Use global variables with caution. they are quite dangerous
An unexpected problem occurs in a running program. A file to be read does not exist. When you want to store some data, the disk is full. You may enter inappropriate data.Ruby> file = open ("some_file ")ERR: (eval): 1: in 'open': No such file or
When a method ends, we may need to clean it up. maybe an open file needs to be closed, and the data in the buffer zone should be cleared. if there is always only one exit point for each method, we can safely put our cleaning code in one place and
The Code is as follows:Copy codeThe Code is as follows:Require 'date'Day = Date. new (2008, 2,-1)End_of_month = day. strftime ('% D'). to_ IYear_and_month = day. strftime ('% Y % m ')For today in 1 .. end_of_month doP sprintf ('% s % 02d',
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