Creating and using modules

Hi,
Newbie Question:

I’m trying to write a simple module/class, in it i’m trying to capture
the repetitive, that i can reuse to make my life easier.

How do i setup this module, so i can make refernces to it?
Where do i need to store the actual file?
I would like to know how can i make references to this module?

if somebody can point me to the right direction, that’ll be very helpul.
appreciate the help.
Parvinder

Parv G wrote:

if somebody can point me to the right direction, that’ll be very helpul.
appreciate the help.
Parvinder

Hi, I’m not sure I 100% understand what you want, but here goes:

You generally set up a class in a stand-alone rb-file. (“class MyClass;
…; end” in myclass.rb, e.g.)
Then, you either put it in one of the system library dirs, or below the
dir that your project is stored in.
Inside your program, you have a line like “require ‘myclass’”, then use
it like any other class.

… Is this what you’re asking, did it answer your question?

Parv G wrote:

if somebody can point me to the right direction, that’ll be very helpul.
appreciate the help.
Parvinder

Well, you can store a module/class in with the rest of your code or as
a separate file and use #require to bring it into your program.
Generally these files are installed in a subdir of Ruby site_ruby
location. For instance, if you are using Debian linux:

/usr/local/lib/site_ruby/1.8/mydir/myfile.rb

Then in your program:

require ‘mydir/myfile’

You should definitely read the PickAxe:

http://www.rubycentral.com/book/index.html

HTH,
T.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs