C
Christoffer Lernö
Hi,
I keep feeling frustrated with my ruby project.
My problem is one of organization.
My code looks a bit like this:
lib/
main.rb
comman ds/
logio.rb
create.rb
chat.rb
server/
io/
protocol/
utils/
And I keep writing code like
require 'commands/logio'
require 'commands/create'
require 'commands/chat'
etc.
What is annoying is the disconnect from what actually happens.
With "require 'commands/logio'" I am actually importing the two
classes LogIn and LogOut as well as ensuring a bunch of other files
are included.
"require 'commands/create'" is importing classes CreateNew and
ReturnDead and so on.
To some extent I can fix this by enforcing a strict 1 file - 1 class
policy, but the problem does not quite go away.
In java it's a bit simpler although far from perfect: "import
commands.*" would import all the classes in one sweep, and of course
the strict 1 file - 1 class policy is maintained in java for public
classes.
What I'd love to have is something like this instead of require:
<logio.rb>
package commands
class LogIn
...
end
class LogOut
...
end
end
<main.rb>
import commands.LogIn
where import goes into the commands dir and just loads that single
class.
Is there something like this available? Any ideas?
/C
I keep feeling frustrated with my ruby project.
My problem is one of organization.
My code looks a bit like this:
lib/
main.rb
comman ds/
logio.rb
create.rb
chat.rb
server/
io/
protocol/
utils/
And I keep writing code like
require 'commands/logio'
require 'commands/create'
require 'commands/chat'
etc.
What is annoying is the disconnect from what actually happens.
With "require 'commands/logio'" I am actually importing the two
classes LogIn and LogOut as well as ensuring a bunch of other files
are included.
"require 'commands/create'" is importing classes CreateNew and
ReturnDead and so on.
To some extent I can fix this by enforcing a strict 1 file - 1 class
policy, but the problem does not quite go away.
In java it's a bit simpler although far from perfect: "import
commands.*" would import all the classes in one sweep, and of course
the strict 1 file - 1 class policy is maintained in java for public
classes.
What I'd love to have is something like this instead of require:
<logio.rb>
package commands
class LogIn
...
end
class LogOut
...
end
end
<main.rb>
import commands.LogIn
where import goes into the commands dir and just loads that single
class.
Is there something like this available? Any ideas?
/C