From: Michael Morin Date: 2008-07-01T02:19:24+09:00 Subject: Re: Something like import/package in java? Christoffer Lern� wrote: > 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: > > > package commands > > class LogIn > ... > end > > class LogOut > ... > end > > end > > > 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 > Not really. If you're worried about namespace pollution, you can put everything into a module. Besides including the module and "importing" everything within it, I don't think there's a way to selectively include classes or methods from the module. What exactly are your concerns? Neatness aside. -- Michael Morin Guide to Ruby http://ruby.about.com/ Become an About.com Guide: beaguide.about.com About.com is part of the New York Times Company