From: Tom Cloyd Date: 2009-01-23T02:00:22+09:00 Subject: Re: class doesn't know about calling program's libraries? Brian Candler wrote: > P.S. It would be extremely helpful if you could boil this down to a very > short program which replicates the problem, and then post that program > in its entirety. > > For example, when I write this: > > ---- 8< ----- > # foo.rb > def main > Foo.new.bar > end > > class Foo > def bar > Readline::readline(">>") > end > end > > %w(readline).each{ |lib| require lib } > main > ---- 8< ----- > > and type "ruby foo.rb" then it runs perfectly. The question is, what's > different between this and what you posted? Does this program run > correctly for you? If so, I suspect the problem lies somewhere outside > what you posted. > > This whole process is extremely useful: > > 1. In the act of minimising the problem, you'll probably find the > solution yourself. > > 2. Even if you don't, then you have made it as easy as possible for > other people on the list to understand and/or replicate the problem, and > hence to find the solution. > > The question then becomes simply: "The following piece of code raises > the exception shown. Why?" Since line numbers in the exception will > match up exactly to the posted code, an experienced coder will likely > see the problem at once. > > Making life easy for other people makes them much more inclined to help > you (both now and in the future), as does demonstrating that you've done > your own homework. There's a very good article on this topic at > http://www.catb.org/~esr/faqs/smart-questions.html > > Regards, > > Brian. > Brian, Thanks for your excellent recommendations. Though I did attempt to present a succinct code excerpt containing my problem, I can see, after reading your comments, that I could certainly have reduced it to essentials, and did not. An excellent idea, and that's how I'll present problems here in the future. Thanks for the correction! And thanks for the link. And thanks for answering my original question about classes' having knowledge of libraries loaded in the calling code. t. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~