一提到ruby你们就会条件反射似地想起rails,彷佛ruby只有一个用途,就是rails。虽然我没写过rails,但我觉得ruby语言自己的魅力远远超过rails这个第三方框架。这是一门值得细细品味的语言,与这门语言一样值得品味的还有一本叫《Metaprogramming Ruby》的书。下面是摘自此书的一段话。express
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这门简洁而又华丽的语言。框架