Ruby is a general-purpose, interpreted programming language.(多用途、解释型)
Ruby is a true object-oriented programming language.(面向对象)
Ruby is a server-side scripting language similar to Python and PERL.(服务器端脚本)
Ruby can be used to write Common Gateway Interface (CGI) scripts.
Ruby can be embeded into Hypertext Markup Language (HTML).
Ruby has a clean and easy syntax that allows a new developer to learn Ruby very quickly and easily.
Ruby has similar syntax to that of many programming languages such as C++ and Perl.
Ruby is very much scalable and big programs written in Ruby are easily maintainable.
Ruby can be used for developing Internet and intranet applications.
Ruby can be installed in Windows and POSIX environments.
Ruby support many GUI tools such as Tcl/Tk, GTK, and OpenGL.
Ruby can easily be connected to DB2, MySQL, Oracle, and Sybase.
Ruby has a rich set of built-in functions which can be used directly into Ruby scripts。
Ruby is a perfect Object Oriented Programming Language. The features of the object-oriented programming language include: 面向对象
Data Encapsulation: 封装
Data Abstraction: 抽象
Polymorphism: 多态
Inheritance: 继承
Defining a Class in Ruby:
To implement object-oriented programming by using Ruby, you need to first learn how to create objects and classes in Ruby.
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. The class Customer can be displayed as:
Variables in a Ruby Class:(Ruby变量)
Ruby provides four types of variables:
Local Variables: Local variables are the variables that are defined in a method. Local variables are not available outside the method. You will see more detail about method in subsequent chapter. Local variables begin with a lowercase letter or _.
Instance Variables: Instance variables are available across methods for any particular instance or object. That means that instance variables change from object to object. Instance variables are preceded by the at sign (@) followed by the variable name.
Class Variables: Class variables are available across different objects. A class variable belongs to the class and is a characteristic of a class. They are preceded by the sign @@ and are followed by the variable name.
Global Variables: Class variables are not available across classes. If you want to have a single variable, which is available across classes, you need to define a global variable. The global variables are always preceded by the dollar sign ($).