Split script into several files

Hi,

I'm a newbie in ruby.

I want to share some classes between different scripts.
Something like a small library.

How can I do this?

Thanks
  Peter

Peter Meier schrieb:

I want to share some classes between different scripts.
Something like a small library.

How can I do this?

Put your code into modules and "require" them.

module Kewl #saved in kewl.rb
class Foo
  def x
  puts "hello"
  end
end
end

And then use it:
require 'kewl'
obj = Kewl::Foo.new
obj.x

···

--
Gruß, Johannes

http://gallery.hehejo.de/jo

Peter Meier wrote:

Hi,

I'm a newbie in ruby.

I want to share some classes between different scripts.
Something like a small library.

How can I do this?

Let's say you have a bunch of Ruby source files, named "class(n).rb" in the
current directory. Do this:

#!/usr/bin/ruby -w

require 'class1.rb'
require 'class2.rb'
require 'class3.rb'

# write code here

···

--
Paul Lutus
http://www.arachnoid.com