irb

 

查祖先

1.9.3-p545 :023 > String.ancestors

=> [String, Comparable, Object, Kernel, BasicObject]

 

String的前面有四个上级

 

过滤方法

Ruby的方法非常多,以至于不得不用grep了。

 

1.9.3-p545 :049 > [].methods.grep /^me/

=> [:member?, :methods, :method]

 

查方法来源

1.9.3-p545 :018 > {}.method :select

=> #<Method: Hash#select>

 

1.9.3-p545 :019 > {}.method :reduce

=> #<Method: Hash(Enumerable)#reduce>

 

method方法可以实现。

 

文档

如果找明确的方法,可以用ri,方便快捷。

ri String.sub

 

对象模型

各种对象语言的原理是类似的,但是内部实现模型是不一样的。Ruby用起来简单,内部很复杂的。

 

 

当你感觉Ruby好用的时候,其实应该感谢Matz的工作。

Kernel模块是核心,很多重要的方法都在里面。

推荐看《Ruby元编程》,书中有详细介绍。

 

相关文章:

  • 2022-01-03
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-08-05
猜你喜欢
  • 2021-04-29
  • 2021-04-21
  • 2021-06-03
  • 2022-02-25
  • 2021-07-11
  • 2021-08-29
  • 2021-11-17
相关资源
相似解决方案