In many cases, when you design your application, you may want to implement a method that is used only for internal use by one object and not for other objects. Ruby provides three keywords to restrict access to methods.
Private: A method that can
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
1 RSS Standard Library
RSS is xml-based, so you can simply parse it as an XML. But, in fact, he has a higher level of proprietary parsers to parse him out. The standard of RSS is also very confusing.
He has a lot of inconvenience, is the standard
1 detect whether the file exists and its size
Filetest's exist? Method can detect whether a file exists:
Flag = filetest::exist? ("Lochnessmonster")
Flag = filetest::exists? ("UFO")
# exists? is a synonym for exist?
If we want to know if the
Ruby handles strings like numbers. We enclose them in single quotes (' ... ') or double quotes ("...").
Ruby> "abc"
"abc"
ruby> ' abc '
"abc"
Single and double quotes have different effects in some cases. A string enclosed in double quotes
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
Ruby Regular Expression
Three methods of representation:
Regexp.new (' ^s*[a-z] ')
/^s*[a-z]/
%r ... {^s*[a-z]}
Test code:
Def show_reqexp (A, re)
if a =~ re
"#{$ '} > #{$ '} '
else
' no match "End end
puts Show_reqexp" ("Fats Waller",/ll/)
Standard type for Ruby:
A. Number
Class Test
3.times {print "X"}
1.upto (5) {|i| Print I, ""}
99.downto {|i| Print I, ""}
50.step (80,5) {|i| Print I, "" "" ""
a = ""
B = "
puts" "
puts A + b
puts integer (a) + integer (b)
end
Output:
1. Read-write properties of member variables: Attr_reader and Attr_writer class Test
Def initialize (name)
@name = name
end
attr_reader:name
attr_writer:name end
test = Test.new ("AAA")
puts test.name
test.name = "BBB"
puts Test.name
If
How is polymorphism defined in Java?
I understand this:
Polymorphism needs to be implemented by means of interfaces, that is, all classes that implement this particular interface are like him.
What is duck type?
This is defined in programming
We often deal with code like this:
Name=person?person.name:nil
Take a property of an object, first determine whether the object is nil, not nil return the object property, otherwise return nil. This kind of code is more disgusting, is there a more
To prove that Ruby really works, Hello World can write so succinctly:
Copy Code code as follows:
Puts ' Hello World '
1. Input/output
Copy Code code as follows:
Print (' Enter your name ')
Name=gets ()
Puts
Ruby, which absorbs Perl's regular expressions and Python's readability, is a very human and flexible way to count values, which can be illustrated here:First , print 7 times "Hello,world", as follows:
Copy Code code as follows:
Recently because to do a class, so yesterday installed a Windows, feel free to do nothing, want to install a Ruby play.
Official Rubygems source Because some resources are placed on the Amazon S3, so sometimes the ventilation, in Linux I use
Notes:
Ruby returns the last value in the method by default.If you need to return more than one value, you can use an array to implement it.A value can be returned by forcing a declaration of return.The basis of the output method is to use puts
(i) Conditional judgmentthe condition is judged as the basic type:
Copy Code code as follows:
If expression
Code
End
If the expression is not false or nil, then the Code section can be executed, so if it is false or nil for
In an MVC based Web application, the application logic and the access to the data are accomplished by C, the controller, in MVC. Therefore, a deep understanding of the controller provided by the MVC framework is essential for developing an efficient,
This article discusses one of the basic services provided in ROR: Action view. Action views enable you to present data more quickly to the user. The services for some action views are described in this article, and an example is given to illustrate
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