How to structure a large Ruby application?

I'm considering writing a (large) desktop application in Ruby (actually a game, think of something like Angband or Nethack using Gtk + for the GUI). I come from C # / background. NET, so I got a little lost on how to structure things.

In C #, I would create many namespaces such as Application.Core, Application.Gui, etc.). Parts of the application that did not need Gui would not reference it using the instructions. From what I understand, in Ruby, the require expression basically does a text insertion that avoids code duplication. What bothers me, with require requests, each file / class will have access to everything else, because the ordering of the required statements is.

I read some ruby ​​code that uses modules as namespaces. How does it work and how does it help?

Not sure what I'm doing here ... Does anyone have any good recommendations on how to structure a large Ruby application? What about some non-trivial (and non-Rails) applications that use Ruby?

+3
source share
2 answers

Ruby is no different than any other language when it comes to structuring your code. Do what seems right and it will probably work. I'm not quite sure what kind of problem you are expecting. Are you worried about name collisions?

Modules are a good way to get pseudo-spatial namespaces, for example.

module Core
  class Blah
    self.def method
    end
  end
end

Core::Blah.method
+3
source

Ruby, . Core Gui Gui Core? ?

"", , , gui .. .

0

Source: https://habr.com/ru/post/1712627/


All Articles