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
There are not many Ruby books. I have collected these books from the Internet. Download them and click images.
Programming Ruby, Second Edition: getting started with Ruby, Version 2, required for learning Ruby
Local variables start with lowercase letters or underscores (_). Local variables do not include nil values before initialization like global variables and real variables.
Ruby> $ fooNilRuby> @ fooNilRuby> fooErr: (eval): 1: undefined local
A constant starts with an uppercase letter. it should be assigned a maximum of once. in the current Ruby version, a constant value assignment only generates warnings rather than errors (non-ANSI eval. RB will not report this warning)
Ruby> fluid
First, you must check whether Ruby has been installed. At the shell prompt ("%" here, so do not enter % ),
% Ruby-V
(-V tells the interpreter to print out the ruby version) and press Enter. If Ruby is installed, you will see information
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
Now let's take the previous examples
Program Of
Code Let's take a look.
The following example is shown in the simple example section.
Def fact (N)If n = 01ElseN * fact (n-1)EndEndPrint fact (argv [0]. to_ I), "\ n"
Because this is the
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.
It can be divided into the following sections:
· Basic implementation
· Reference the original object in the iteration, or directly change the value of the array instead of returning a new array
· Input infinite parameters to Iteration
·
The String in Ruby is mutable, unlike the String in java and C # is immutable. For example
Copy 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
Git repository outputGit archive -- format = tar -- prefix = actasfavor/HEAD | (cd/home/holin/work/& tar xf -)Output to the/home/holin/work/actasfavor/directory
Posted by holin At May 16,200 8Load controller and model in plugins
# Include hook code
As ruby is a pure object-oriented language, everything is an object. methods are objects and classes are objects ..., therefore, self has many environments. Only by distinguishing the meanings of self in different environments can we better
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
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
In this chapter, we will discuss more Ruby process control.CaseWe use case statements to test ordered conditions. As we have seen, this is close to the switch in C and Java, but it is more powerful.Ruby> I = 8Ruby> case I| When 1, 2 .. 5| Print "1 ..
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|
From the technical point of view, ruby itself is really great, making the work of programmers easy and interesting!The following code demonstrates how to find a prime number within 100:Copy codeThe Code is as follows:Using System;Namespace
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.