Split script into several files

P

Peter Meier

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
 
J

Johannes Held

Peter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,211
Messages
2,571,100
Members
47,695
Latest member
KayleneBee

Latest Threads

Top