Ror has been blooming abroad for a long time, but it has always been a bit cool in China. Except javaeye, I rarely hear the success stories of domestic ror. On the infoq Chinese site a few days ago, I saw a piece of news from Jeff Xiong. I
1. syntax check (-C)
Execute IN RUBYProgramWhen using the "-c" command, the Ruby interpreter does not execute the program, but checks whether the program is to be executed.CodeCorrectness
Ruby-C eg. Rb
2. Enable warning (-W)
Run the program with
Modules and blocks are special in ruby.
The module has a namespace to organize classes, methods, and constants.Module also has the Mixin method. You can include a module in the class to implement the instance method mixed into a module.
Sample:
I just posted a few songs in the music space and typed a few Ruby words.
Code Popularity
Require
'
Net/HTTP
'
Count
=
1
..
100000
#
Define an array
Count. Each {
#
Each
|
Index
|
#
Element is
To obtain the content of an HTTP/FTP address in Ruby, you can easily use the open-Uri library.
Open-Uri library is included in Ruby's standard additional library, path: lib/oepn-uri.rb
After referencing this additional library, you can open
(1) Everything in ruby is an object, including a constant.For example, you can use the. Class Attribute to view the type of an object. You can see that the type of constant 1 is fixnum, and 1 is just an instance of fixnum. You can also use the-37
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Class
A
Def
SayPuts
"
I'm
"
EndEnd
Class
B
A
Def
Say
#
When super is added, it will not be overloaded and the subclass
In addition to class, Ruby also supports module, which has two functions:1. namespace used as a group method and constant to prevent name conflicts2. Mixin classes can be mixed in. Instances of Mixin module classes have module methods.
If
"% 05d" % 123 the result is "00123""% 02x" % 10 returns "0a""% 03x" % 10 the result is "00a""% 010x" % 10 returns "000000000a" (9 prefixes 0)"% 10x" % 10 returns "a" (with a prefix of 9 spaces)
We can see that the first digit is the prefix,
There are three types of modifying keywords for Ruby member access, which are the same as C.1 private can only be the method called by this object2 protected can only be called for this object and its sub-objects3. Public allows any object to call
The iterator is a feature of advanced languages and is very easy to use.
For example, array Iteration[1, 2, 3]. Each {| n | puts N. to_s}(1. 100). Each {| n | puts N. to_s} iterates each element
String Iteration"ABDC". each_byte {| CHR | printf "
Complaints when learning Ruby
I accidentally started to learn Ruby. After a New Year's Day, I learned Ruby for two years (in fact, just a few days ).
In general, it is a bit rejected because it does not feel good.
I learned a little about VB
1. = (equal to) and! = (Not equal)
Returns true and flase if the values of the two objects are equal.
A = 1; B = 1.0; A = B # True
2. eql?
Returns true and flase if the values and types of the two objects are equal.
A = 1; B = 1.0; A. eql? (B)
1. download the latest Ruby version in the http://rubyinstaller.org and install it directly. (Rubyinstaller-1.8.7-p370.exe) (view ruby-V)
2. Download The devkitfile (devkit-tdm-32-4.5.2-20151129-1559-sfx.exe), decompress the package, and select the
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
Ruby Syntax:
1: Variable2: Comment3: embedded document4: Reserved Words
Ruby currently uses the ASCII character set. It can recognize uppercase and lowercase letters. In addition to the variable and part of the direct amount, you canAdd spaces and
========================================================== ==========================================1. Can the methods in the Controller call each other?2. The @ variable defined in the control method is not an instance variable. It seems that it
The following pattern is commonly used to define method names in ruby.
Def method_name (arg1, arg2) # Some codeend
However, it is often seen in the code of books or other authors that=? !These three special weird symbols serve as the suffix of 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.