Let's look at a more interesting program. This time we're going to test whether a string matches a description produced by the Concise pattern (concise) encoding.
In these patterns, some characters or character combinations have unique meanings,
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
First, the methodRuby's method definition allows you to set a default value for a parameter, but you cannot have a parameter without a default value after an argument with a default value (Allow * and &), meaning that the following method definition
We know the top-level domain, what is the self of the domain defined?
Copy Code code as follows:
Puts self #main
Puts Self.class #Object
We know that when a method is invoked, if there is no object to accept, the default is
Longest public subsequence, LCS, dynamic programming implementation.
#encoding: Utf-8 #author: Xu Jin, 4100213 #date: Nov, #Longest-commom-subsequence #to find a longest commom subse Quence of two given character arrays by using LCS algorithm #
First, traversing all files under the folder, output file name
Copy Code code as follows:
def traverse_dir (File_path)
If File.directory? File_path
Dir.foreach (file_path) do |file|
If file!= "." and File!= "..."
An iterator is nothing but a collection of methods supported. An object that stores a set of data members is called a collection. In Ruby, arrays and hashes can be called collections.
The iterator returns all the elements of a collection, one after
Ruby and Python are too similar, and most of the trade-offs are a reason for personal preference. For example, I feel that Python's "There is" just one way to do it. "Better than Ruby's There are many to do it." It's not just about teamwork, it's
The string in the Ruby language is mutable, unlike a string in Java, C #, which is immutable. Like what
Copy Code code as follows:
str1= "ABC"
str2= "ABC"
In Java, for literal strings, a table is maintained inside the JVM,
In terms of technology alone, Ruby is really cool, making the programmer's job a fun and easy task!The following code shows how to find the prime number within 100:
Copy Code code as follows:
Using System;
Namespace Mersenne
{
The code is as follows:
Copy Code code as follows:
Require ' date '
Day = Date.new (2008, 2,-1)
End_of_month = Day.strftime ('%d '). to_i
Year_and_month = Day.strftime ('%y%m ')
For today in 1..end_of_month do
P sprintf ('%s%02d ',
1. Search first and then execute, otherwise the first line of execution program
2. function definition, class definition, module definition execution, causing these things to be defined
3. The statement that causes the program to exit, or to the
The new version of Will_paginate has abandoned this practice, instead of using the gem approach, this article through the establishment of a foobar application to understand the use of will_paginate.
==============================
C:\>rails foobar-
Like Ruby Metaprogramming, puppet and chef use a lot of Ruby's language features to define a new deployment language.Share a few in the actual project used in the scene, limited capacity, if there is a better program, please leave a message to me:
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
In older versions of Ruby, the return value of an assignment statement is the return value of the method that sets the property. In Ruby1.8, the value of an assignment statement is always the value of the parameter and the return value of the method
If you test the RESTful service by hand, it will be very tedious. Of course, there are some browser plug-ins that can help you manually test by using a visual interface, such as postman, rest console, but every time a system version is updated, you
Some time ago to see a lot of people write the next sister script, I also write a
Module Commonhelper
require ' Nokogiri '
require ' Open-uri '
def down_load_xmz
site_url = ' http:// Www.xxx.com "for
index_page in 1..141
In the rails principle there is the idea of simplifying controller, enriching model. A simple inheritance optimization is shown below with an example. Especially when you have a change self variable in your method.
Suppose we have the following
Minitest, a new generation of ruby testing framework, has become the built-in test framework for Ruby 1.9, and it is said to be the default test framework for Rails 4, promising.
Minitest Why is the latest Ruby and Rails preferred, and what are the
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.