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
#scanweb. RB
#用法ruby scanweb.rb www.jb51.net to save the current results in C:\1.txt
Require ' net/http '
Filename= file.new (' C:\1.txt ', "w+")
If $*[0]==nil
Puts "hehe, no input URL"
Else
h = net::http.new ($*[0], 80)
RESP, data = H.get
The Fruit class in the previous section has two real variables, describe the type and state of the fruit. Until a custom inspect method is written for this class, we understand that it does not make a reasonable explanation for a fruit that lacks
We may need to clean up when a method is finished. Perhaps an open file needs to be closed, the buffer data should be emptied, and so on. If there is always a single exit point for each method, we can safely place our cleanup code in a location and
Conditional judgments are present in the programming language, and the conditional judgments in Ruby are similar to those in Java, but there is a slight difference
Conditions in ruby conditional judgment:
1 can use comparison operations such as ==,
Recently, a lot of people with rails to develop micro-trust project friends on the GitHub began to use Weixin_rails_middleware, weixin_authorize, but also many talked about Ratchet, Spring Festival began to now, has been doing micro-letter
C # implements Ruby's negative index
public class Invertiblelist: list
{public
new T This[int index]
{
get
{
if (Index >= 0) return Base[index];
if (Count + Index = 0)
Base[index] = value;
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:
Large data operation involves data cleaning step or script processing is more convenient, the following introduction pig loading HDFs file calls Ruby script processing data, and then return data flow to the pig processing a simple case.
Note: Ruby
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
I have nothing to do, with Mechanize do a can download the campus photo album Code.
It's a little shabby .... The main is based on the address of the album to analyze the user ID and photo album ID, and then simulate the request album page, and
Recently packaged servers have increased the number of APK packets, each manual RM operation too cumbersome, so spent a few minutes to write a can be specified in the directory according to the last modified time and wildcard matching for bulk
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.