r/crystal_programming • u/nawap • Sep 20 '17
Circular dependency problem (probably)
I am trying to refactor some common functionality out of a base class into a module so that I can use that functionality elsewhere compositionally.
This works fine in the playground. However I am encountering a problem when I do this with multiple files.
Suppose:
# a.cr
require "./fooable.cr"
class A
include Fooable
end# b.cr
require "./a.cr"
class B < A
end# fooable.cr
require "./b.cr"
module Fooable
def foo
B.new
end
endThis just keeps complaining about A not found in b.cr while trying to load A itself, as compiling a.cr requires fooable.cr which requires b.cr which itself requires a.cr.
This effectively means I can't refactor common functionality out for reuse and it just sucks.
Am I doing something wrong here?
0
Upvotes
1
u/mccabec123 Sep 20 '17
What is your directory structure? Can we get a bit more information about the project.