How can I choose which version of a module to include dynamically in Ruby?

前端 未结 3 1975
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 07:20

I\'m writing a small Ruby command-line application that uses fileutils from the standard library for file operations. Depending on how the user invokes the applicat

3条回答
  •  [愿得一人]
    2021-02-20 07:48

    So what if it's private?

    class Worker
      def initialize(verbose=false)
        if verbose
          (class <

    This includes FileUtils::something in particular's Worker's metaclass - not in the main Worker class. Different workers can use different FileUtils this way.

提交回复
热议问题