In rails, the process of sending a request (/users) is as follows:1), Browser send request (/users)2), rails routes will route the request to the Users_controller index method3), Users_controller callback use user model to get all user4, user model
What's block?
In Ruby, block is not uncommon. The official definition of block is "a parcel of code". Of course, I don't think this explanation will make you more aware.
A simpler description of block is "a block is a piece of code stored in a
Agent mode
Demand:
Xiaoming let Xiao Li Chase for him (send doll, send flowers, send chocolate)
Code with no agents:
#-*-Encoding:utf-8-*-
#追求者类
class Pursuit
attr_accessor:mm
def Initialize (mm)
@mm = mm
End
def give_dolls
Have seen "Ruby design mode" before, but gradually forgot. Now bought a big talk design pattern, it does not look so boring, by the way the code in Ruby implementation.
Simple Factory mode:
#-*-Encoding:utf-8-*-#运算类 class Operation
Installation of Ruby
Pay attention.
OS X or Linux is better
Implementation of different versions: C + +, C, Java
This time C Ruby
Installation method
Linux or OS X has pre-installed
Package Manager (APT, yum, Brew), not
Ruby Environment variablesThe Ruby interpreter uses the following environment variables to control its behavior. The ENV object contains a list of all the currently set environment variables.For Unix, use the ENV command to view a list of all
Download Rubyinstaller.
Link: http://rubyinstaller.org/downloads/. Run the installation directly
Note You need to add the following in the environment variable: \ruby\bin
Test command: Ruby-v
Install RubyGems.
Ruby traverses the contents of the file, the basic idea is to read row by line printing, is also a more common method:#!/usr/bin/env ruby#encoding:utf8file = File.Open ("/tmp/abc.txt") file.each_line do |line| Print Lineendfile.closeAnother way of
#api New rulesRails New Companyname-projectname-web-api--api#gem New rulesBundle Gem Companyname-projectname-gem#ローカルgemのbuild & Install#ソース構造Companyname-cloud|--companyname-projectname-web-api|--companyname-common-gem#companyname-common-gemのgem
Http://ruby-doc.org/stdlib-2.3.3/libdoc/optparse/rdoc/OptionParser.html#method-c-new read Lib's documentation and make a note. Optionparser This class is used to set command line parameter options when writing commands on the Lines tool. Getoptlong
The definition is simple: the instance variable @ begins, class variable @@ at the beginning to read some articles and books, the current understanding of (in fact, still do not understand, first remember, the wrong to change):
Class
(1.. - do |x| if 5) end The use of the above flip-flop, you can be understood to be greater than or equal to 5 and less than or equal to 10 of the number printed out, that is understood as puts X if x >=5 && x but note you can not be written as
An object modelKernel ModuleKernel.private_instance_methods.grep (/^pr/)Private method1 If a method recipient is not your own, be sure to specify a recipient2 Private methods can only specify one implied recipient (private method of the tunable
When your first started coding, errors were probably the last thing you wanted to see.After all, it's not a far stretch to associate "error" with "I messed up".Hopefully by now you've come to appreciate the value of a good error message. Take a look
IteratorsAn iterator is a method in which a yield statement is used, and the method of yield is called an iterator, and the iterator is not necessarily iterative, and data is transferred to the block passed to the method.Yield passes the data to the
First, class variablesIn Ruby, you can define a class variable for a class, and the value of a class variable is shared by all instances (objects) of the class.is somewhat similar to static variables in other languages, such as Java, but differs
First, global variablesGlobal variables are supported in Ruby, and global variables in Ruby are characterized by the following:1) identifiers are marked with a $ start2) Global variables can be referenced from anywhere in the program3) nil. Let's
Workaround:1.koala Visual Compilation tool,Locate the engine.rb file under the sass-3.3.7 module in the installation directory, such as the following path:C:\Program Files (x86) \koala\rubygems\gems\sass-3.3.7\lib\sassENGINE.RB in this file, add a
Common shortcut keys :The first level must beCtrl+alt+g: EjectGenerateCtrl+alt+l: Formatting codeALT+F1: Toggle View(Project, Structure, etc.).Alt+f2: Pop-up Preview window, choose Browser to open Web pageAlt+insert: Equivalent tofile| New, but
Tutorial on configuring SERVER_NAME domain name items in the Flask framework of Python, flaskserver_name
SERVER_NAME in Flask mainly performs the following two tasks:
Assists Flask in generating absolute URLs (for example, embedding website URLs
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.