From: Jason Watson Date: 2010-03-13T23:48:56+09:00 Subject: Re: Newbie Help : Object --0015174c0f2823e6620481afbfe2 Content-Type: text/plain; charset=UTF-8 You might get more help if you show some code. On Sat, Mar 13, 2010 at 1:15 PM, Jerome David Sallinger < imran.nazir@yahoo.co.uk> wrote: > Hello, > > This question may be more to do with my understanding of OOP that the > actual contructs of Ruby so please be patient with me. > > I am interested in visualizing data so am teaching myself to Programming > using Ruby via computer graphics. I am steadily building up my knowledge > and experience by writing by and executing rudimentary code around the > new thngs I learn. Now I'm stuck so i'll make the question as simple as > I can: > > I create a window of Ball objects based on a Ball class that I have > written. Each Ball object is instantiated at a randon x,y location on > the screen and has random speed. > > Each Ball object is able to reverse its driection (bounce) if it hits > the edge of the window. > > If I have two balls and I want to detect whether they instersect with > each other as they move around the screen this is simple enough; the > ball class has an intersect() method which i can use to pass in a > reference to the other ball object. But what if there are are random > number of balls. How do I make it such that any Ball object would be > aware of the location of any other Ball object without having to resort > to nested for loops where I check the location of each Ball against > every other Ball? > > Any ideas > -- > Posted via http://www.ruby-forum.com/. > > -- jbw --0015174c0f2823e6620481afbfe2--