The standard practice is to put all or most of the require statements at the top of the file. Files should be designed so there is as little dependency as possible to other files.
The problem you have is that you have designed the file display.rb
to be dependent on the class Hello
.
When you say this:
class Hello::Display
end
It is the same as:
class Hello
class Display
end
end
But the difference is that in the first case Hello
needs to be defined before you can say Hello::Display
. Since Hello
has not been defined when you put the require at the top of the file you will get the error.
You can fix it like this:
class Hello
class Display
# ..your Display code here..
end
end
Or like this:
# Predefine Hello as a class name
class Hello
end
class Hello::Display
# ..your Display code here..
end