Alias from module root

phoenix

#1

I have the following modules:

Foo.Bar
Bar.Module

And I’d like to do this within a module:

alias Foo.Bar
alias Bar.Module

However I get (module Foo.Bar.Module is not available)

Is there a way to make that work?

Something like we’d do in ruby ::Bar.Module to access it from the root.

Thanks


#2

Maybe try to reverse order

alias Bar.Module
alias Foo.Bar

The problem with alias Foo.Bar is You are defining Bar as being Foo.Bar

That might not be a good idea to have 2 modules with the same name… (Foo.Bar and Bar)


#3

Something like we’d do in ruby ::Bar.Module to access it from the root.

Elixir.Bar.Module is an equivalent. But yes, better to avoid conflicting names if possible.


#4

Sounds good, thank you both for the advice!


#5

It’s hacky, but I suspect if you reversed the order of your alias declarations, it might work