Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a module inherit from another module in Ruby

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.

like image 485
beakr Avatar asked Apr 15 '12 00:04

beakr


1 Answers

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 
like image 81
DigitalRoss Avatar answered Oct 04 '22 20:10

DigitalRoss