Ruby 请教关于 include 的问题。

ericzhu · 2012年03月27日 · 最后由 suupic 回复于 2012年03月27日 · 2506 次阅读
module A
end

class B
  include A 
  # 为什么self.include A 是错误的
  # 但是 self.send :include, A 又行呢。
end

我的问题有两个

  1. send 调用方法 和 直接调用方法的区别是?
  2. include 是哪个类的方法。

Thx

send 可以调用私有方法。 include 是 Module 的私有方法。

匿名 #2 2012年03月27日

#1 楼 @pongyo bingo. private method 不能显示指定 receiver

#1 楼 @pongyo 明白了,thank you

#3 楼 @EricZhu 元编程那本书里有一节讲私有方法和 send

需要 登录 后方可回复, 如果你还没有账号请 注册新账号