From: Asfand Yar Qazi Date: 2005-02-20T20:54:42+09:00 Subject: Re: Getting a method or class within a file Pit Capitain wrote: > Asfand Yar Qazi schrieb: > >> I want to be able to do the following: >> >> lots of Ruby files are in a directory, each containing stuff and a >> method 'init_file'. I want to be able to 'require' each file, and >> then call the 'init_file' method within that file. >> >> Each file will have its own 'init_file' method, so I can't just do a: >> >> require 'file' >> init_file >> >> because the init_file method will have been defined before hand. > > > Not that I would recommend that, but you can do > > require 'file1' > init_file > > require 'file2' > init_file > > because the init_file method of file2 will overwrite the init_file > method of file1. > > But: of course this is bad style. Where do your Ruby files come from? > Can't you wrap the code in each file in a class or module? > It's also thread-unsafe. You're right. I think what I'll do is to have a combination of a Module name and a filename that will allow there to be an init method contained within 'Module', contained within 'file'. But then I'll have to store 2 entries: filename and module name. But I suppose that's ok. Perhaps I should use the following syntax: Module@path/to/file.rb to show that a module is in a certain file?