When values are all shaped, sort by the values of the hash:h = {'a' = =1,'b ' ==2,'C ' +5,'d' = 4} H.sort {|a,b| a[1]b[1]} Output: [["a", 1], ["b", 2], ["D", 4], ["C", 5]] When we need to sort the hash, we cannot use the Sort method as
When you are sharing objects in multi-threaded processing, multiple threads can modify the same object at the same time, possibly in an inconsistent state, and be aware of it when used. Example: Test.rb x = 010.times.map do |i| Thread.new do
intends to learn a scripting language, but do not know which to choose, the Internet to find information, finally difficult to choose in Ruby and Python, so list other people's evaluation, choice, opinion, etc. for themselves and others reference;In
ARGFAn Io object that connects all the files specified in the argv into a file. If argv is empty, then it represents standard input. Synonyms $ArgvAn array that contains all the parameters specified by the command line. Synonyms $*DATARepresents all
#numbers are classified as certificate integer, floating-point number float (corresponding to double in other languages), and plural complex#integers are divided into fixnum and Bignum,fixnum and Bignum to each other, and these are the operations
#Encoding:utf-8require"Open-uri"require"Timeout"require'RubyGems'require"Nokogiri"URI="http://api.map.baidu.com/direction/v1?mode=driving&origin=&destination= Peking University &origin_region= Beijing &destination_region= Five Street, &output=xml&ak=
# Close command display @ echo off # message ECHO now, listing the controller, please not shutdown the DOS file! # Switch to the current path. Put the. BAT file and the. RB file together. set Pa = % Cd % # execute the ruby script Ruby test. rbpause
Rails3 is coming out, and it's time to start learning. You can find a good tutorial on the Internet: http://railscasts.com/episodes, which can be downloaded.
Unfortunately, only 10 entries are displayed on each page and cannot be downloaded in
Let's write a function to calculate the factorial. The mathematical definition of the factorial is as follows:
N! = 1 (when n = 0)= N * (n-1 )! (Other Cases)
In Ruby, you can write as follows:
CopyCode The Code is as follows: def fact (N)
If
I didn't want to write or install Ruby, but some people in several puppet groups are confused about Ruby installation. So here I will briefly introduce how to install Ruby.
PS: Now gitlab, Capistrano, puppet, and other software use Ruby. The latest
Class array def iterate! (& Code) # note that the & Symbol self is used here. each_with_index do | N, I | self [I] = code. call (n) end endendarr = [1, 2, 4] arr. iterate! Do | n ** 2end # [1, 4, 9, 16]
When I read the code today, it was masked
1. Constants
Although Ruby only requires uppercase letters of a constant, we recommend that you use uppercase letters of a constant name for better readability.
Class personsFinger = 10; # define ConstantsPuts "Everyone has" + finger. to_s + "root
Each
The simplest iterator is to access all elements collected continuously.
[1,3,5,7,9].each { |i| puts i }
Output result:
1
3
5
7
9
The unique function is to implement the for loop of the Ruby language. Because the built-in loop
Matz is a professional software engineer working in netlab. JP, a famous open source company in Japan, and he is also a high-profile open source evangelist in Japan. He participated in several open-source software projects, including cmail. This is
1. Install the system dependent Software Package
sudo apt-get install build-essential git curl imagemagick nodejs redis-server libcurl4-openssl-dev libxml2-dev libxslt-dev libmysqlclient-dev
2. confirm that the curl version is 7.32 or later. if the
The Code is as follows:Copy codeThe Code is as follows:Require 'date'Day = Date. new (2008, 2,-1)End_of_month = day. strftime ('% D'). to_ IYear_and_month = day. strftime ('% Y % m ')For today in 1 .. end_of_month doP sprintf ('% s % 02d',
I. MethodsThe Ruby method definition allows you to set default values for parameters. However, parameters without default values (* and &) cannot be followed by parameters with default values &), that is to say, the following method definition is
The new version of will_paginate has abandoned this practice and switched to the gem method. This article builds an application named foobar to understand the usage of will_paginate.====================================C: \> rails foobar-d mysqlC: \>
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