Ruby comes with a set of predefined variables $: =Default search path (array of paths)Other Ruby special variables:$! The location where the last error message [email protected] is generated $ _ gets recently read string $. the number of lines
I. Comparison statements
Most of them are the same as other languages. Note ,
Condition Statement
The following forms
If
If... else... end
If... elsif... else... end
Unless (if not)
Case... when
x=1if x==1 puts 1elsif x==2 puts
Ruby objects are strictly encapsulated: they can only access their internal states through defined methods. The member variables used by the method cannot be directly accessed outside the object. However, they can be directly accessed through getter,
Module
Similar modules also have class method and instance method.The instance object cannot be generated if the module does not have a new one.The class method is called a module method in the module and can be called directly.
Module Foo def self.
In the Java language, the launch mechanism is provided. Through the launch mechanism, this object can be constructed using strings to obtain all methods of the object (including private methods) and call private methods, you can change the value of
Loop structures are indispensable in programming languages, so loops in Ruby also have their own custom rules.
While we focus on the loop structure, we need to know two factors: 1) the condition of the loop; 2) the content of the loop execution
Ruby
After installing the Rails framework, you also get a new command line tool: rails. This tool can be used to construct each new Rails application.
Why do we need such a tool-I mean, why don't we just copy the most handy editor and write each line of
New ClassCopy codeThe Code is as follows: ruby script/generate Model :...Ruby script/generate Model Item name: string age: integerRemove ClassCopy codeThe Code is as follows: ruby script/destroy Model
New ControllerCopy codeThe Code is as follows:
Upgrade mac OS Mavericks to the latest version. Json loading error:Copy codeThe Code is as follows:Gem install json-v '1. 8.1'
Building native extensions. This cocould take a while...ERROR: Error installing json:ERROR: Failed to build gem native
This article uses Nginx, Rails, Mysql, and Redis as an example. It is similar to other web servers, languages, databases, and cache services.The following are three layers to facilitate subsequent reference:
1. Client Cache
A client often accesses
First, let's take a look at the NewRelic report.
Average response time of the last 24 h
Pages with high traffic)
Several actions of traffic volume:
TopicsController # show
UsersController # show (miserable, mainly because GitHub API requests are
% Q
Used to replace double quotation marks. When you need to put a lot of quotation marks in the string, you can directly use the following method without adding a backslash (\ ") One by one before the quotation marks (\")Copy codeThe Code is as
Recently, many friends who have used Rails development projects began to use weixin_rails_middleware and weixin_authorize on Github. Many people have talked about Ratchet, which has been developing since the Spring Festival, now I am releasing it on
The ruby language is still updated frequently. However, a large number of versions make Library compatibility a big problem. Some gems explicitly do not support ruby earlier than a specific version, while some gems are not compatible with higher
Ruby Stone scissors cloth game
Copy codeThe Code is as follows:# Encoding: UTF-8Arr = ['stone ', 'scissors', 'bo']Win_arr = [['stone ', 'scissors'], ['scissors ', 'cloth'], ['cloth ', 'stone']# Add the random computer value to the result
Tips
Puts Mechanic: AGENT_ALIASES can print out all available user_agent
Puts mechanic.instance_methods(false)Output all methods of the Mechanism module
Puts mechanic. instance_methods () Outputs all methods of the mechanic module and the
Profile. rb is the profiler prepared for the Ruby program. It can count and output the running time of each method to locate the performance bottleneck of program execution. This time, we will use it to analyze the running time of the script. 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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service