I've just started on my first decent-sized Ruby project and before the
number of files spirals too far out of control I wanted to ask for some
advice on what the accepted "best practice" for organizing files and
code might be. I've tried to download and look at some largish Ruby
projects but I don't have a clear picture of what the Right Thing is.
Specifically, just say I add some methods to an existing standard class
like Array, what would be the best convention for choosing where to
store the added code? Here's a concrete example: let's say I want to
add a "eol?" method to the StringScanner class?
class StringScanner
def eol?
return true if self.eos? or self.match?(/[\n\r]/)
false
end
end
At the moment I have stuck it inside another file (for one of the
classes that needs to use this method). But what if I want to keep it
in a separate file? What would be the conventional name for such a file
(evidently not "strscan.rb" because that would most likely cause
confusion with the StringScanner implementation when doing a "require
'strscan'").
Likewise I had a similar doubt when I wanted to added some assertions
of my own in addition to those which come with Test::Unit::Assertions.
The original assertions are defined in a shared location terminating in
"test/unit/assertions.rb"; but how would I name my additions file if I
wanted to keep things in a separate file? For the time being I've just
stuck the new code at the top of another file, but somehow it just
doesn't feel right...