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
This article mainly introduces a few Ruby tips to share, this article explains the code block sequence calls, mainly said that the array in blocks in the use, Hash#fetch, create code snippets and other tips, the need for friends can refer to the
Most of Ruby's built-in types are similar to other programming languages. Mainly have strings,integers,floats,arrays and so on. However, only scripting languages, such as Ruby,perl, and awk, provide support for built-in expression types. Regular
Get the current date and time:
The following is a simple example to get the current date and time:
#!/usr/bin/ruby-w
time1 = time.new
puts "current time:" + time1.inspect
# Time.now is a synonym:
time2 = Time.now
puts "current time:" +
In the Java language, a launch mechanism is provided by which the object can be constructed from a string, can get all the methods of the object (including private methods), can invoke the private method, and can change the value of the member
1.require ' Upyun ' reference Upyun 2.upyun = Upyun::rest.new (bucket,operator,password,options,endpint)3.res = Upyun.put ('/1/2/3/4/5/hi.jpg ', File. New ('/workspace/hi.jpeg ')) 4.puts "Response is #{res}" Look at the return information if it is
1. Definition of similarityWe define, then, we set, then, | C|=s, then the similarity of p=,p (0,1)2. Design of similarity detection algorithmAlgorithm design:Defines 4 characters as a string, divides the t1,t2 into strings, and if the remaining
# Ruby's gsub string substitution feature1. You can use hash to replace the corresponding string:"Hello 123 World". Gsub (/hello|world/, ' hello ' = ' hello ', ' world ' = ' world ') # = "Hello 123 World"Although support for the second parameter is
Ruby, like other object-oriented languages, uses classes to organize methods, and then instantiate classes to create objects.1. Construction methodUsing double quotation marks is the literal construction method of a string, or you can use the named
I mainly use two plug-ins: rinari and Yari.
Rinari supports fast jump to multiple files in the rails project. In addition, it provides the grep tool, which I found useful. The shortcut keys are easy to remember.
Yari provides an Emacs interface
Ruby on Rails can be installed in two ways.
1. Direct Installation
We can download Ruby on Rails from the official website.: Http://rubyonrails.org/
After the download is complete, you can directly install it. It cannot be installed in a path
I. Railway
1.1 create a rails Application
Program
$ Rails app_name
Optional:
-D, database = xxx specifies to install a database (MySQL Oracle PostgreSQL sqlite2 sqlite3), which is a database by default
-R, ruby-Path = specifies the ruby
Chapter 2 Structure and running of Ruby programs
The ruby annotation starts with # And ends until the end of the line. Ruby does not have/*... */C style annotations.
If # appears in the string or regular expression literal, it is a part of a
The. vcproj file is no stranger to Visual Studio (VC ++) users, and. vcxproj is released after vs2010, The. vcproj file is changed
. Vcxproj. They are all XML-based files, so there are many libraries for parsing them. Here I will use libxml.
The
ActiveRecord programming guide in Ruby on Rails, rubyonrails
Avoid modifying the default ActiveRecord (Table Name, primary key, and so on) unless you have a very good reason (such as a database not under your control ).Put the macro-style method
Examples of common events such as bind, hover, and toggle in jquery, jquerytoggle
1. $ (document). ready ()
$ (Document). ready () is a typical method in jQuery to respond to the onload event built in JavaScript and execute the task. It has a
Sidekiq in RailsIntroduction
Sidekiq is a multi-threaded background task processing system. Before it came out, a Resque product (made on Github) exists, because Resque is a multi-process model, therefore, when the number of tasks increases, the
GitHub advocates a summary of Ruby coding styles, while github advocates ruby code.
Source code layout: 1. All source files are UTF-8 encoded2. indent with two spaces3. Use Unix-style line breaks (\ n) and windows (\ r \ n ). You can use git config -
Object array sorting in Ruby and Ruby object array sorting
Sorting of Ruby object arrays
The author has just come into contact with Ruby, because he previously thought that the script language syntax is not standardized and he is somewhat biased
Page 3Overview
Description and execution: Python and Ruby are highly interactive;○ Compilation and execution: Pascal, C, fast.N local execution, such as C, C ++;N virtual machine execution, such as Java, C #. ○ Dynamic languages, such as
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