Algorithm principle:
Compare the adjacent elements. If the first one is bigger than the second one, swap them both.Do the same work for each pair of adjacent elements, from the first pair to the end of the last couple. At this point, the final
A real variable starts at the @, its scope is limited to the self object. Two different objects, even if they belong to the same class, can have real variables of different values. From outside the object, the real variable cannot be changed or even
Let's write a function that calculates the factorial. The mathematical definition of factorial is as follows:
N! = 1 (when n==0)
= n * (n-1)! (Other cases)
In Ruby, you can write this:
Copy Code code as follows:
def fact (N)
If
When you need to add one or more actions to a RESTful resource (do you really need it?) ), using the member and collection routing.
# get
' subscriptions/:id/unsubscribe '
resources:subscriptions
# good
resources:subscriptions do
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
The class variables in Ruby, a lot of articles are not recommended, the main reason is that some of his features are prone to make some mistakes, especially in the wide use of meta-programming.The initial contact class variable may feel that he and
Recently doing a scan code login function, for this I also searched the internet about the implementation of the scan login. When this function was completed, I decided to organize the whole realization, so that I can see it later and also
The count-taking method in Ruby is the most humane and flexible in the language I touch, which can be illustrated here for example:First, print 7 times "Hello,world", as follows:7.times{puts "Hello,world"} #在这里, puts function is equivalent to print+
Yum install RubyGem install rails-VWithout-V, the progress is not displayed, just like a dead machine, but not actually a dead machine.Yum install ruby-develNo plug-ins will be installed.Yum install SQLite-develHe will be stuck in SQLite
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
The array size in Ruby can be changed at any time. The elements in the array only save references to objects.I. Definition
A = array. New ()
A = array. New (5) Create an array of five nil Elements
A = array. New () Create five arrays whose
In ruby on rails, SideKiq is used for background tasks. railssidekiq
Environment: ubuntu14.4, ruby2.1.5, rails4.2
1. A new rais project: rails new active_job -- skip-Bundle
Enter the project folder: cd active_job
Open the Gemfile: vim Gemfile
Change
Explain the single-piece method and single-piece class in Ruby, and explain the ruby single-piece Method
Single-piece Method
Ruby allows adding methods to a single object. This method takes effect only for a single object. It is called a
Use the Markdown method in Ruby on Rails, railsmarkdown
The Redcarpet and pygments. rb are used to implement Markdown syntax and code syntax highlighting respectively:
Https://github.com/vmg/redcarpetHttps://github.com/tmm1/pygments.rbHttps://github.
The Ruby language has many special functions that deserve further research. For example, the syntax is different from that of other programming languages. Here we will understand some concepts related to Ruby's special syntax.
Basic Syntax of
NOIP record and noip record
I have just finished my study today, and I have a holiday. I only have time to write my blog.
My province is a weak Province. It seems that there are specialized OI teachers in three schools, and I have never heard of
Explain the instance_eval method in Ruby and its comparison with class_eval, rubyinstanceeval
Instance_eval Method
This BasicObject # instance_eval is a bit similar to the bind method in JS. In different cases, bind transmits this to the object,
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