[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Split script into several files

Peter Meier

9/7/2006 5:30:00 PM

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
2 Answers

Johannes Held

9/7/2006 5:48:00 PM

0

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://www...
http://gallery.he...

Paul Lutus

9/7/2006 6:26:00 PM

0

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.ara...