How to override static class method using module in Ruby?

前端 未结 3 868
再見小時候
再見小時候 2021-02-02 16:11
module Imodule
  ???
end

class Some
  include Imodule

  def self.imethod
    puts \"original\"
  end
end

Some.imethod
# => \"overrided\"

How to c

3条回答
  •  清酒与你
    2021-02-02 16:28

    If this really is an interview question to test deep understanding of Ruby features, then the answer is trivial: Ruby doesn't have class methods. Nor does it have static methods. It most certainly doesn't have static class methods. If you have a deep understanding of Ruby features, heck, even if you have just a superficial familiarity with Ruby, you know this. Ergo, it's a trick question.

提交回复
热议问题