1. Japanese to UTF-8Differences between iconv. New ('cp932', 'utf-8') and iconv. New ('shift _ JIS ', 'utf-8')
Iconv. New ('shift _ JIS ', 'utf-8') does not support the following formats:
When bytes 001-18 xxxxxxx, you can only replace the bytes
1. Search for the begin statement first, and execute the statement if it is found; otherwise, execute
ProgramThe first line
2. When it comes to function definitions, class definitions, and module definitions, these things are defined.
3. Run
A real variable starts with @ and Its range is limited to the self object. two different objects can have real variables with different values even if they belong to the same class. from outside the object, real variables cannot be changed or even
The behavior of an object depends on its class, but we often know that a specific object requires a specific behavior. in many languages, we have to get into the trouble of defining another class, even if it is only used for the next ing. in Ruby,
I have written a simple unit test library for myself in Ruby over the past few days. It feels a little DSL.
It seems that there is no ruby format. Use Lua to make it together.
Sample Code:
Code highlighting produced by Actipro CodeHighlighter
1. Open and read files
File = file. Open ("cnblogslink.txt") file. Each {| Line | print "# {file. lineno}.", line} file. Close
Output:
1.Community 2. News
3. Community
4. News
5. Recruitment
6. Bo Wen
7. Group8. Flash9. Network
ArticleDirectory
Variables
Conditions
Loops
Error Handling
Methods
Classes
Using code from other files
In the previous blogs, I introduced some ironruby-related content, because ironruby is in ruby. net, so its
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
I. Create a table (using Ruby script/generate model attach) and generate a model.
Open dB/migrage/007_create_attaches.rb and change it
Class createattaches Def self. Up
Create_table: attaches,: force => true do | T |
T. Column: name,: string #
Object-oriented It is a confusing wording. object orientation makes others think you are fashionable. ruby claims to be an object-oriented scripting language, but what exactly is "Object-Oriented "? We already have a variety of answers, but all
You can create an array by listing elements in square brackets and separating them with commas (,). The ruby array can adapt to different object types.
Ruby> ary = [1, 2, "3"][1, 2, "3"]
Just like the string mentioned above, Arrays can be
# Scanweb. Rb
# Use Ruby scanweb. RB www.jb51.net to save the current result in c: \ 1.txt
Require 'net/http'Filename = file. New ('C: \ 1.txt ', "W + ")If $ * [0] = NilPuts "hehe, no URL entered"ElseH = net: http. New ($ * [0], 80)Resp, Data =
From the technical point of view, Ruby itself is really nice.ProgramThe work of Members becomes easy and interesting!The followingCodeDemonstrate how to find a prime number less than 100:
Copy code The Code is as follows: using system;
Namespace
Class String def has_one_in? (String_Arr) has = false string_Arr.each {| word | has = self. include? (Word) if has break end} has endenddef decode_subject (sub) if sub. include? ("B? ") Encode_str = sub. match (/= \? (.*?) \? =/). To_s
Recently I started to learn ruby. to practice the basic syntax, I used ruby to write an insert sorting algorithm, which may be a trace of translation from C #.
1. Insert sorting
Seq = [3, 4, 9, 0, 2, 5, 9, 7, 1]1. upto (seq. length-1) do | I |If
Global variables start with $. They can be accessed anywhere in the program. Before initialization, the global variables have a special value nil.
Ruby> $ fooNilRuby> $ foo = 55Ruby> $ foo5
Use global variables with caution. they are quite
We always want to classify unknown events. When it happens, passing a piece of code as a parameter to other methods is the easiest solution, that is, we want to process code like processing data.A new process object can be created through proc:Ruby>
Some important differences between ruby and c # are as follows:1. ruby is a dynamic language, and c # Is a static language-that is, after an object is new, ruby can dynamically add some attributes or methods to the object instance (as does
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