Making a module inherit from another module in Ruby

inheritance, module, ruby

Solution

In fact you can define a module inside of another module, and then include it within the outer one.

so ross$ cat >> mods.rb
module ApplicationHelper
  module Helper
    def time
      Time.now.year
    end
  end
  include Helper
end

class Test
  include ApplicationHelper
  def run
    p time
  end
  self
end.new.run
so ross$ ruby mods.rb
2012

Problem

I'm making a small program for Rails that includes some of my methods I've built inside of a module inside of the `ApplicationHelper` module. Here's an example: ``` module Helper def time Time.now.year end end module ApplicationHelper # Inherit from Helper here... end ``` I know that `ApplicationHelper < Helper` and `include Helper` would work in the context of a class, but what would you use for module-to-module inherits? Thanks.

Original source