---
title: "rubybook"
author: "cdhychen"
date: "2011-08-09T16:06:22Z"
tags: []
categories: ["编程语言"]
slug: "rubybook"
draft: false
lastmod: "2011-08-09T16:06:22Z"
id: 1143611
url: "https://cdhychen.iteye.com/blog/1143611"
---

Ruby 语言是一种[动态语言](http://cdhychen.iteye.com/view/1458275.htm)，它与[Python](http://cdhychen.iteye.com/view/21087.htm)、[Smalltalk](http://cdhychen.iteye.com/view/76337.htm)和[Perl](http://cdhychen.iteye.com/view/46614.htm)这3种编程语言有些类似。Ruby语言起源于[日本](http://cdhychen.iteye.com/view/1554.htm)，它的研发者是日本人[松本行弘](http://cdhychen.iteye.com/view/1438214.htm)（Matsumoto Yukihiro）。松本行弘在1993年开始着手Ruby语言的研发工作，他开发Ruby语言的初衷是为了提高[编程](http://cdhychen.iteye.com/view/3281.htm)的效率。 1995年12月Matz推出了Ruby的第一个版本Ruby 0.95。

　　Ruby语言的主要特点如下：

　　**1．纯的面向对象语言**

　　在Ruby中，一切皆是[对象](http://cdhychen.iteye.com/view/2387.htm)。下面举一个例子来更直观地说明Ruby语言的这一特点。

　　在[Java](http://cdhychen.iteye.com/view/29.htm)中，求一个数的绝对值的代码如下。

　　int c = Math.abs(-20);

　　而在Ruby语言中，一切皆是对象，也就是说“-20”这个数也是一个对象，因此，求一个数[绝对值](http://cdhychen.iteye.com/view/220956.htm)的Ruby代码形式如下。

　　c = -20.abs

　　这样的代码编写方式是不是更形象一些呢？

　　**2．解释型[脚本语言](http://cdhychen.iteye.com/view/76320.htm)**

　　Ruby 语言是解释型脚本语言，它既有脚本语言强大的字符串处理能力和[正则](http://cdhychen.iteye.com/view/1203256.htm)表达式，又不失解释型语言的动态性。一方面，在最初设计Ruby语言时，Ruby的研发者松本行弘考虑到文字处理方面的需要，他借鉴了Perl语言在文字处理方面的成功经验。另一方面，松本行弘将Ruby语言设定为一种解释型语言，Ruby 的动态性使得由Ruby语言编写的程序不需要事先[编译](http://cdhychen.iteye.com/view/69568.htm)即可直接运行，这为程序的[调试](http://cdhychen.iteye.com/view/322913.htm)带来了方便。同时，这一特点可以实现开发过程中的快速反馈。

　　**3．其他特点**

　　（1）动态载入。可以在运行时候重定义自己，类也可以在运行时[继承](http://cdhychen.iteye.com/view/125322.htm)或取消继承。

　　（2）自动[内存管理](http://cdhychen.iteye.com/view/4541016.htm)机制。

　　（3）多精度[整数](http://cdhychen.iteye.com/view/71484.htm)。

　　（4）[迭代器](http://cdhychen.iteye.com/view/925158.htm)和[闭包](http://cdhychen.iteye.com/view/648413.htm)。

　　（5）[开源](http://cdhychen.iteye.com/view/9664.htm)项目。有大量活跃的[社区](http://cdhychen.iteye.com/view/49629.htm)支持Ruby语言。