Rexml is a processor written entirely in Ruby, with a variety of APIs, two classic APIs that are distinguished by dom-like and sax-like. The first is to read the entire file into memory and then store it as a layered form (that is, a tree). The
Introduced
This is a short introduction to Ruby and it takes only 20 minutes to complete the reading. This assumes that the reader has already installed Ruby, and if you are not installing it, please visit the official Ruby website for download and
Global variables begin with $. They can be accessed anywhere in the program. The global variable has a special value nil before initialization.
ruby> $foo
nil
ruby> $foo = 5
5
ruby> $foo
5
Global variables should be used with caution. They are
A local variable starts with a lowercase letter or an underscore (_). Local variables do not contain nil values like global and real variables before initialization.
ruby> $foo
Nil
ruby> @foo
nil
ruby> foo
ERR: (eval): 1:undefined local variable
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 #
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
{
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-
#scanweb. RB
#用法ruby scanweb.rb www.jb51.net to save the current results in C:\1.txt
Require ' net/http '
Filename= file.new (' C:\1.txt ', "w+")
If $*[0]==nil
Puts "hehe, no input URL"
Else
h = net::http.new ($*[0], 80)
RESP, data = H.get
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:
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
In an expression, when Ruby sees a name like a, it needs to decide whether a is a local variable reference or a call to method a with no parameters. Ruby uses a heuristic approach to judge this situation. When ruby resolves the source code file, it
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
C # implements Ruby's negative index
public class Invertiblelist: list
{public
new T This[int index]
{
get
{
if (Index >= 0) return Base[index];
if (Count + Index = 0)
Base[index] = value;
If you want to see the source code for the ActiveRecord update_attribute function, a more common approach is to search for Def Update_attribute directly from the Rails source. Blog The Pragmatic Studio introduces a more convenient technique to
Because Windows file deletion mechanism is different from Unix like, so does not guarantee that the following code can be used in Windows, which child upper I test in Windows also good AH!
Copy Code code as follows:
#!/usr/bin/ruby
First, the preface
IronRuby is a ruby implementation in. NET, and ruby.net this Open-source project, the main difference is that IronRuby leverages Microsoft's newest DLR, while Ruby.net is fully leveraging the original CLR implementations.
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