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

willx · December 15, 2021 · Last by Phil123321 replied at September 02, 2022 · 412 hits

一个 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 closed this topic. 15 Dec 22:35
willx reopened this topic. 27 Jan 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

You need to Sign in before reply, if you don't have an account, please Sign up first.