From: HiddenBek Date: 2007-12-31T03:40:04+09:00 Subject: Re: newbie question - how to use multiple source files The second file must require the first: require 'first_class_file' This would generally go at the top of the file, but anywhere before FirstClassFile is referenced is fine. The require method looks at each path in the $LOAD_PATH global variable, then attempts to find a Ruby source file or C extension that matches the name you pass in. Check out http://www.rubycentral.com/pickaxe/tut_modules.html#S4 for more details. In your example, the public and super calls are unnecessary. Public is the default visibility, and, as both of your classes inherit from Object, there's no need to call the initializer of the superclass. It's also quite common to have multiple Ruby classes in the same source file. Ruby classes are often small, and many people find it easier to manage a small handful of larger files than dozens of tiny ones. On Dec 30, 1:36 pm, Ben Hoffmann wrote: > I'm coming from Java, and am trying to understand how to break upo code > into more than one file. So in this example, I have one class in the > first file, another in the second file, and I want to create an object > from the first class, but from the second file. Environment - Aptana on > XP machine. See below: > > 1) First file named first_class_file.rb: > > class FirstClassFile > > public > > def initialize > super > puts "Hello from First Class" > end > end > > my1stObject = FirstClassFile.new > > 2) Second file named second_class_file.rb: > > class SecondClassFile > > def initialize > super > puts "Hello from Second Class" > end > end > > my2ndObject = SecondClassFile.new > > my3rdObject = FirstClassFile.new > > 3) Console result of running second file: > > Hello from Second Class > second_class_file.rb:11: uninitialized constant FirstClassFile (NameError) > > Question - What obvious thing am I doing wrong? > Thanks! > - Ben