Reputation: 27
I am having 2 different file test1.rb and Report.rb as follows :
test1.rb
module List
module Report
constants = Report::Category.constants.collect{|c| c.to_s}
end
end
In Report.rb
Class Report < ApplicationRecord
module Category
CONSTANT1 = 1
CONSTANT2 = 2
end
end
So I get an error in test1.rb saying undifined method category for list::Report. It is accessing the module list::Report insted for Report class from Report.rb. Is there a way to access another class/module with same name as the current file module?
Upvotes: 0
Views: 811
Reputation: 3019
Try
constants = ::Report::Category.constants.collect{|c| c.to_s}
(note ::
before Report
that causes constant's lookup to start looking from the outmost context)
Upvotes: 2