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 or
The iterator was not invented by Ruby. It is widely used in all kinds of object-oriented languages. In Lisp, it's just not called that. However, the concept of iterators is not familiar to many people, so we will do a more detailed description here.
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
Command mode is a design pattern with a higher rate of object behavior usage, alias: Action (Action), Transaction (transaction)
Intent: To encapsulate a request into an object so that you can parameterize different requests, queue or log request
Max method
b=[1,3,55,777,2,4,6,8,0]
For numeric data, Max gets the maximum value of the array, and Min gets the minimum value of the array.
B.max => 777
b.min => 0
There is no real meaning to the size of the string array
Brief introductionA single case pattern is one of the simplest forms of design patterns. The purpose of this pattern is to make an object of a Class A unique instance of the system. To do this, you can start by instantiating it from the client.
1. Installation RVM
Curl-l Https://get.rvm.io | Bash-s Stable
RVM is a command-line tool that provides management and switching of multiple versions of the Ruby environment, as well as different gemset depending on project management.
If
Ruby Environment variablesThe Ruby interpreter uses the following environment variables to control its behavior. The ENV object contains a list of all the currently set environment variables.For Unix, use the ENV command to view a list of all
Avoid the metaprogramming of infinite loops.
Do not confuse the core class when writing a function library (do not use monkey patch).
code block forms are best used in string interpolation forms.When you use a string interpolation form, always
A single line string that needs to be interpolated and embedded with double quotes uses% () (abbreviated as%Q). Multi-line string, preferably with Heredocs.
# bad (no interpolation needed)
% (some text)
# should to be ' some text '
#
If you just need to find the text of the string, do not use regular expressions: string[' text '
For simple structures, you can query directly using the string[/re/] approach.
Match = string[/regexp/] # Get content of matched regexp
The built-in support for regular expressions is usually limited to scripting languages such as Ruby,perl and awk, which is a disgrace: Although regular expressions are mysterious, they are a powerful tool for text processing. It is very different to
Generalization, the basic data types in Ruby are all class types, but for the convenience of writing and reading, it provides a simpler way to write basic data types.
Type of a value
Integers support binary, octal, decimal, hexadecimal, which
1. The class variable name begins with @@ 开始 and a class variable is shared by all instance objects of this class; the instance variable name begins with the @, each instance object has its own different instance variables;
2, class variables must
Complexity of Time: Theta (n^2)
Bubble sort
Copy Code code as follows:
Def Bubble_sort (a)
(a.size-2). Downto (0) do |i|
(0..I). Each do |j|
A[J], a[j+1] = a[j+1], a[j] if A[J] > a[j+1]
End
End
Return a
End
#!/usr/bin/ruby-w
#
require ' digest/md5 '
if argv.empty?
Puts "Usgae: #$0 path"
exit 0
End
dir_name=argv.shift
def dir_md5sum (path)
md5s=array.new
If File.directory? (path)
Dir.new (path). Each do |file|
Next
This chapter deals with some practical issues.
Statement delimiter
Some languages require a certain type of punctuation, typically a semicolon (;) to end each statement of the program. Ruby uses the shell's SH and csh convenience. Multiple
Note: Ruby Windows Installer Pack please go to http://rubyinstaller.org/download installation.
Installed a Ruby193, wrote the first Ruby program, to record their own learning bit.First in Ruby's new folder, sample, and then add a new file, name
while (when ...) ) loop
While conditionStatement 1; Statement 2; Statement...End
Single While loop
(statement 1; Statement 2; Statement... ) While condition
Until (until ...) ) loop
Until condition = While not
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