码迷,mamicode.com
首页 > 编程语言 > 详细

Ruby,一门简单又华丽的语言

时间:2015-01-17 17:49:43      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

一提到ruby大家就会条件反射似地想起rails,似乎ruby只有一个用途,就是rails。虽然我没写过rails,但我以为ruby语言本身的魅力远远超过rails这个第三方框架。这是一门值得细细品味的语言,与这门语言同样值得品味的还有一本叫《Metaprogramming Ruby》的书。下面是摘自此书的一段话。

The Great Unified Theory “The Ruby object model is a beautiful place,”
Bill notes, with a dreamy expression on his face. “There are classes,
eigenclasses, and modules. There are instance methods, class methods,
and Singleton Methods.” At first glance, it all looks very complex.
Look closer, and the complexity fades away. If you put eigenclasses
together with regular classes and modules, you end up with the seven
rules of the Ruby object model:
1. There is only one kind of object—be it a regular object or a module. ?2. There is only one kind of module—be it a regular module, a
class, an eigenclass, or a proxy class.
3. There is only one kind of method, and it lives in a module—most often in a class.
4. Every object, classes included, has its own “real class,” be it a regular class or an eigenclass.
5. Every class has exactly one superclass, with the exception of BasicObject, which has none. This means you have a single ancestors
chain from any class up to BasicObject.
6. The superclass of the eigenclass of an object is the object’s class. The superclass of the eigenclass of a class is the eigenclass
of the class’s superclass. (Try repeating that three times, fast! Then
look back at Figure 4.5, on the preceding page, and it will all make
sense.)
7. When you call a method, Ruby goes “right” in the receiver’s real class and then “up” the ancestors chain. That’s all there is to know
about the way Ruby finds methods.

当我读到这段话的时候我简直要疯了。用七条原则就可以对一门语言下定义,试问还有哪门语言做得到(至少就我学过的语言来说还没有第二门)。简洁本身就是一种美,ruby又在其简洁的逻辑假设基础上,衍生出复杂多变的特性来,简直可以用华丽来形容。其实很多庞杂的理论体系都是从几条平淡无奇的假设演绎出来的。
我希望能循由这七条线索,与大家一起品位ruby这门简洁而又华丽的语言。

Ruby,一门简单又华丽的语言

标签:

原文地址:http://www.cnblogs.com/haipenge/p/4230702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!