0

How can you define c method that is accessible from class One and Two?

module MyGem
  class One
    def a
      c
    end
  end

  class Two
    def b
      c
    end
  end
end

1 Answers1

0

There is few ways, for example inheritance vs mixins.

Using mixins, you can define a Module and include in your classes.

module MyGem
  class One
    include Mixin

    def a
      c
    end
  end

  class Two
    include Mixin

    def b
      c
    end
  end

  module Mixin
    def c
      ...
    end
  end
end
Community
  • 1
  • 1
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73