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
The fruit class in the previous section has two real variables, indicating the fruit type and status respectively. it was not until we wrote a customized inspect method for this class that we knew it would not give a reasonable explanation of a
We always want to classify unknown events. When it happens, pass a piece
Code Is the easiest solution, that is, we want to process code like processing data.
A new process object can be created through proc:
Ruby> quux = proc {| Print
Ruby processes strings like numbers. We enclose them with single quotation marks ('...') or double quotation marks.
Ruby> "ABC""ABC"Ruby> 'abc'"ABC"
Single quotation marks and double quotation marks have different functions in some cases. A
1. send messages to the object
We can directly send messages to objects:
Ruby
Code
Copy code The Code is as follows: Class helloworld
Def say (name)
Print "hello,", name
End
End
HW = helloworld. New
HW. Send (: Say, "world ")
We usually use HW.
Let's look at a more interesting program. This time we will test whether a string matches the description produced by concise pattern encoding.
In these pattern modes, some characters or character combinations have unique meanings, including:
Copy
The iterator was not invented by Ruby. it is widely used in various object-oriented languages. this is also true in Lisp. even so, the concept of iterator is not familiar to many people, so we will give a more detailed introduction here.
You know,
Ruby has some special modules that are useful. For example, the Ruby module OpenURI introduced here is a common Ruby module. We need to be familiar with its features.
Ruby on Rails directory files
Ruby function pointer concepts
Ruby Rmagick
BKJIA exclusive Article] With the rapid development of computers, more and more programming languages have emerged. In the past 10 years, due to the speed of development, Java has become the leader in programming languages. As Java continues to
To install Ruby, go to the Ruby official website to download the Windows Installation Package of Ruby1.56. After installing ruby, open the Dos window and enter Ruby-v to display it.Ruby 1.8.6 (patchlevel 0) [i386-mswin32] indicates that Ruby has
What is a method? In OO programming, we do not want to directly manipulate the data of an object from the outside; on the contrary, the object itself knows how to manipulate itself (when properly requested ).You may say that we pass a message to an
In the subclass, we can modify the object behavior by reloading the parent class method.Ruby> class Human| Def identify| Print "I'm a person. \ n"| End| Def train_toll (age)| If age | Print "CED fare. \ n ";| Else| Print "Normal fare. \ n ";| End|
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,
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>
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> $ foo5Use global variables with caution. they are quite dangerous
The Fruit class in the previous section has two real variables, indicating the Fruit type and status respectively. it was not until we wrote a customized inspect method for this class that we knew it would not give a reasonable explanation of a
# Scanweb. rb# Use ruby scanweb. rb www.jb51.net to save the current result in c: \ 1.txtRequire 'net/http'Filename = File. new ('C: \ 1.txt ', "w + ")If $ * [0] = nilPuts "hehe, no URL entered"ElseH = Net: HTTP. new ($ * [0], 80)Resp, data = h. get
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 String in Ruby is mutable, unlike the String in java and C # is immutable. For exampleCopy codeThe Code is as follows:Str1 = "abc"Str2 = "abc" In java, for literal strings, the jvm maintains a table internally. Therefore, in java, str1 and str2
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