Like many programming languages, Ruby also provides a complete data structure to store and manage the objects. Arrays are created using square brackets and a single object reference list separated by commas.
presidents=["John", "Richard", "Gerald",
This article mainly introduces the collection of multiple Ruby Traversal folder code instances, this article summed up 4 pieces of code, small series recommend the last method, because it is very simple and elegant, need friends can refer to the
Regular match
Speaking of Ruby, of course, the regular expression mechanism of the regular expression as a strong matching language has been more and more used in different fields, from string verification, matching, to Web page extraction and so
Max method
b=[1,3,55,777,2,4,6,8,0]
For numeric data, Max gets the maximum value of the array, and Min gets the minimum value of the array.
B.max => 777
b.min => 0
There is no real meaning to the size of the string array
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
The built-in support for regular expressions is usually limited to scripting languages such as Ruby,perl and awk, which is a disgrace: Although regular expressions are mysterious, they are a powerful tool for text processing. It is very different to
Complexity of Time: Theta (n^2)
Bubble sort
Copy Code code as follows:
Def Bubble_sort (a)
(a.size-2). Downto (0) do |i|
(0..I). Each do |j|
A[J], a[j+1] = a[j+1], a[j] if A[J] > a[j+1]
End
End
Return a
End
#!/usr/bin/ruby-w
#
require ' digest/md5 '
if argv.empty?
Puts "Usgae: #$0 path"
exit 0
End
dir_name=argv.shift
def dir_md5sum (path)
md5s=array.new
If File.directory? (path)
Dir.new (path). Each do |file|
Next
First, let's take a look at Newrelic's report.
Average response time of the last 24h
Those pages with high traffic (Action)
Access to several Action cases:
Topicscontroller#show
Userscontroller#show (more miserable, mainly GitHub API
Ruby, as an object-oriented language, must be involved in the operation of objects, this time it involves methods.
Call Method-Object. Method Name (argument 1, Argument 2, ..., argument N)
Classification of methods:
1. Instance method: As the
Notes:
Ruby returns the last value in the method by default.If you need to return more than one value, you can use an array to implement it.A value can be returned by forcing a declaration of return.The basis of the output method is to use puts
An active record abstracts the concept of a database connection and helps the application to handle the details of the underlying database links, in lieu of the active record using a generic invocation to delegate the details to a set of database
One of the objects in the ActiveRecord corresponds to a row of tables in the database, and the object's properties correspond to the columns of the table, and you may notice that our order class does not mention anything about the Orders table
ActiveRecord is an object-relational mapping (ORM) layer provided by rails, starting with the basics of active record, connecting databases, mapping tables, accessing data, and more.
Active record uses basic ORM mode: tables are mapped to classes,
In the previous essay, we have added the input validation to the products creation page, this time the content is very simple, to slightly beautify the products of the list page.
1. Open the app\views\admin\list.rhtml file, you can see the
In the previous essay, we completed the deletion of a table product, you must have noticed that we have not added any validation, such as price, we can enter any character, without error prompts. This time, let's take a look at how to add the
This article will focus on how to build a ROR development environment under different operating systems and, at the end, detail how to install and configure the MySQL database under Windows operating systems.
Construction of development environment
1. Input: Yum install Ruby1.1 Error downloading Packages If installation file is wrong:Input: Yum Clean allinput:yum Makecache, at this point if error cannot find a valid BaseURL for repo:base/7/x86_64,Open Vi/etc/sysconfig/network-scripts/ifcfg-enp4
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
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