The current Ruby language is hot among programmers, and the open source community is constantly having new ruby apps. Thin and Sinatra are the best of the Times.But new things always have a maturity, just as any upgrades have a price. Sinatra and
A running program often encounters unexpected problems. A file to read does not exist; When you want to save some data, the disk is full; The user may enter inappropriate data.
ruby> file = open ("Some_file")
ERR: (eval): 1:in ' open ': No such
Now let's analyze the code of some of the previous example programs Bache.
The following example appears in a simple Example section.
def fact (N)
If n = 0
1
Else
n * Fact (N-1)
End
End
print fact (argv[0].to_i), "\ n"
Because this is the first
The local database creates the order table.
Suggestions include the following fields, referring to the official API (HTTPS://PINGXX.COM/DOCUMENT/API):
Order_no:required
The merchant order number, suitable for each channel requirement for
Ruby annotationNote hides a row for the Ruby interpreter, or part of a line, or several rows. You can use the character (#) at the beginning of the line:
# I'm a note, please ignore me.
Alternatively, the annotation can follow the same
A single exception uses the FAIL keyword only to catch an exception and throw it over and over again (because you are not failing here, but are accurate and intentionally throwing an exception).
Begin
fail ' Oops '
rescue => error
Use:: To refer to constants (including classes and modules) and constructors (such as Array () or nokogiri::html ()).Never use:: To invoke a method.
# bad
someclass::some_method
some_object::some_method
# good
Private
Private functions can only be invoked in the context of this class and subclass, and can only be accessed by self.
This means that the private function can only be accessed within this object.
The access rights of an object instance
One, string operation
string interpolation
1.#{}: Any legitimate Ruby code placed in #{} will be evaluated and replaced with an evaluation result inserted in the original location
2. Single and double quotation marks differ:
Double quotes allow
Focus on private and protected
Public
The default is public, the global can be accessed, this does not explain
Private
C + +, "private" means "private to this class", but Ruby is the "private to this instance".In C + +, for Class A, you can
One, problems and ideas
Recently in the rails + react + MySQL basic framework to write a CMS + client project, which involves the image upload and display, the following simple ideas, as for the deployment of the project, should be in the end of
Sometimes it is convenient to be able to store any Ruby object directly in an attribute, in the same way that an active record supports serialization, transforms a Ruby object into a ymal string, and stores the string in the database field
In the last content, we demonstrated how to build a simple shopping cart, this time the content is very simple, to add error handling to the shopping cart.
Concurrent processing is an unavoidable problem for web systems, and we mimic a scenario of
In the previous section, we demonstrated how to build a list of items, and this time we built a simple shopping cart based on the previous content.
1. First we want to create a table that holds customer shopping information:
Database scripts:
Developers have predicted that rails cannot be the mainstream of business applications. But as rails has become more and more popular in web development, more and more companies are starting to invest more attention on rails, while rails
The following installation steps can be installed under/usr/local/rbenv, and all users can share rbenv. #rbenv安装 (/usr/local/rbenv) #安装依赖, the root user is required Yum install-y git Yum Install-y readline-devel Yum install-y openssl-devel
In the process of reading no matter what the problem, welcome to communicate togetherEmail:[email protected]qq:1494713801First, how to define the associationThere are often associations between the two model, and in order to solve the complex
Using MVC thinking to understand the design structure of the Ruby on Rails framework, rubyrails
In rails, the process of sending a request (/users) is as follows:1). the browser sends a request (/users)2) Rails routes requests to the index method of
Ruby captures web images and ruby captures images.
Some time ago, I saw a lot of scripts written by my sister, and I wrote one myself.
Module CommonHelper require 'nokogiri 'require 'open-uri 'def down_load_xmz site_url = "http://www.xxx.com" for
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