Is it possible to make an alias for a module in Ruby?

Modules in Ruby aren’t really that special, so you can just assign them to another constant:

[4] (pry) main: 0> module TestModule
[4] (pry) main: 0*   def self.foo
[4] (pry) main: 0*     "test"
[4] (pry) main: 0*   end  
[4] (pry) main: 0* end  
=> nil
[5] (pry) main: 0> tm = TestModule
=> TestModule
[6] (pry) main: 0> tm.foo
=> "test"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)