module Superpower
# instance method
def turn_invisible
...
end
# module method
def Superpower.turn_into_toad
...
end
module Fly
def flap_wings
...
end
end
end
Class Superman
include Superpower
...
def run_away
# how to call flap_wings?
# how to call turn_invisible?
end
def see_bad_guys(bad_guy = lex_luthor)
#is this correct?
Superpower.turn_into_toad(bad_guy)
end
end
嗨,我看到了一些我无法理解的 ruby 代码。你如何从超人类中调用flap_wings?是否可以从类中调用实例方法?包含模块和嵌入模块有什么区别?为什么以及何时应该这样做?