Ruby Ruby 的 module 经常用来做 mixin,如何能隔离其中的一些方法令其为私有?

willx · 2021年12月15日 · 最后由 Phil123321 回复于 2022年09月02日 · 412 次阅读

一个 method 过长我们通常需要拆分成一些小 method,而这些小 method 是不希望暴露给外界的,这时有办法隔离他们吗?

module Foo
  def bar
    bar_sub_1
    bar_sub_2
  end

  def bar_sub_1
  end

  def bar_sub_2
  end
end
module Foo
  def bar
    bar_sub_1
    bar_sub_2
  end

  private # 加上这行!

  def bar_sub_1
  end

  def bar_sub_2
  end
end

原来 module include 的时候可以声明 private,我还以为不可以

willx 关闭了讨论。 12月15日 22:35
willx 重新开启了讨论。 01月27日 21:44

You can tell whether a review is professional from the first sentence. One of the most difficult aspects of a great best essay uk is providing unique, non-plagiarized material. The website will not rank well if the material is plagiarized. When it comes to selecting the top essay writing service reviews,

Spend your free time interesting in the 1 dollar deposit casino Canada

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