When you call a method, Ruby does two things.
1. Find this method. This method is called a method lookup.
2. Implement this method. To do this, Ruby needs something called self.
Such a process-discovering a method to execute-occurs in every
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
Ruby has three classes of variables, one constant, and two strict pseudo variables (pseudo-variables). There are no types for variables and constants. Although there are some drawbacks to the untyped variable, there are more advantages and good
Object-orientedis a very confusing language. It's all about being object-oriented and making people think you're trendy. Ruby claims to be an object-oriented scripting language, but what is "object-oriented"?We've got all kinds of answers, but all
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
When an HTTP response is a format that is different from the one in which it exists (XML and JSON), some additional formatting needs to be parsed, creating a format that you are accustomed to, and using it in a category. Idiomatic formats should be
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 '
#
Name an identifier in English.
# bad-identifier using non-ascii characters
заплата= 1_000
# Bad-identifier is-a Bulgarian word, written with Latin letters (instead of Cyrillic)
Zaplata = 1_000
# good
salary = 1_000
Name
Return,break,next the use of these keywords involves jumping out of scope, and their difference lies in the scope of the different keywords jumping out, because there are blocks of code that cause some places to pay extra attention.
Return
Common
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
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
1.whenever
First, the whenever is based on the Linux cron service, so there is no direct way to use the gem on the Windows platform. Whenever should technically be a cron translator, translating the Ruby code into a cron script, and handing the
Rails accelerates and simplifies the development of Web applications, but it's not mature enough, especially at high-end enterprise-level features. On the other hand, the Java platform and its virtual machines, libraries, and application servers
Files in the same directory, such as/USR/LOCAL/RUBY/FOO.RB and/usr/local/ruby/bar.rb two files.If you are directly in the FOO.RB
Require ' bar '
A bar.rb error cannot be found at execution time.This is because the running
/home/
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
The code is simple, there's no more nonsense.
#coding: Utf-8
require ' Sinatra ' require ' Omniauth ' require ' "Omniauth-github ' use
rack::session:: Cookies
with Omniauth::builder do
provider:github, ' b478ae6b31dd730b20d1 ', ' 89f67d361fb3
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.