Your foo/stuff/baz.rb
does not contain a require
statement, and you will not tell anything about the main program. Therefore, I think that you just do not download the code.
Ruby does not have automatic downloads depending on the path to the folder; you must explicitly download the source code. In your case, you will need require_relative '../bar'
in the file foo/stuff/baz.rb
Then the class Foo::Bar
is known:
require_relative '../bar' module Foo module Stuff class Baz < Bar end end end p Foo::Stuff::Baz.new p Foo::Stuff::Baz.ancestors
Result:
#<Foo::Stuff::Baz:0x00000002ff3c30> [Foo::Stuff::Baz, Foo::Bar, Object, Kernel, BasicObject]
The initialization method Foo::Bar
executed.
A more realistic architecture would be to use a main file in which you load all the code files, for example:
foo.rb foo/bar.rb foo/stuff/baz.rb
and foo.rb will contain:
require_relative 'foo/bar' require_relative 'foo/stuff/baz'
source share