Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Is it possible to call functions from different scripts in a Rubyscript ?

Reply
Thread Tools

Is it possible to call functions from different scripts in a Rubyscript ?

 
 
Axel Etzold
Guest
Posts: n/a
 
      05-21-2004
Dear experienced Rubyists,

I am new to Ruby.
In other script-like softwares (with more limited purposes), such as
Matlab,
it is possible to call functions (i.e., modules),
from other files, and to pass arguments to them,
which allows to spread the code and re-use from different
scripts it.
Is this possible in Ruby , too ? Or is there a
principal constraint from object-oriented programming,
which forbids this ?

Thank you for your help!

Best regards,

Axel Etzold





 
Reply With Quote
 
 
 
 
Ryan Paul
Guest
Posts: n/a
 
      05-21-2004
On Sat, 22 May 2004 03:08:44 +0900, Axel Etzold wrote:

> Dear experienced Rubyists,
>
> I am new to Ruby.
> In other script-like softwares (with more limited purposes), such as
> Matlab,
> it is possible to call functions (i.e., modules),
> from other files, and to pass arguments to them,
> which allows to spread the code and re-use from different
> scripts it.
> Is this possible in Ruby , too ? Or is there a
> principal constraint from object-oriented programming,
> which forbids this ?
>
> Thank you for your help!
>
> Best regards,
>
> Axel Etzold


it sounds like you are talking about importing... you can write functions,
classes, modules, etc, in one file and access them quite easily from
another, using the 'require' keyword. Use the word 'require', followed by
the name of the file you want to include. you only need the prefix of the
file, (you leave off the .rb part) and you surround the name with single
quotes.

file1.rb

class MyClass1
def myfunc1
puts "function1 called!"
end
end

----
file2.rb

require 'file1'

a = MyClass1.new
a.myfunc1

 
Reply With Quote
 
 
 
 
Axel Etzold
Guest
Posts: n/a
 
      05-21-2004
Dear Ryan,

That solved it! Thank you very much !

Best regards

Axel
Am Fre, den 21.05.2004 schrieb Ryan Paul um 20:48:
> On Sat, 22 May 2004 03:08:44 +0900, Axel Etzold wrote:
>
> > Dear experienced Rubyists,
> >
> > I am new to Ruby.
> > In other script-like softwares (with more limited purposes), such as
> > Matlab,
> > it is possible to call functions (i.e., modules),
> > from other files, and to pass arguments to them,
> > which allows to spread the code and re-use from different
> > scripts it.
> > Is this possible in Ruby , too ? Or is there a
> > principal constraint from object-oriented programming,
> > which forbids this ?
> >
> > Thank you for your help!
> >
> > Best regards,
> >
> > Axel Etzold

>
> it sounds like you are talking about importing... you can write functions,
> classes, modules, etc, in one file and access them quite easily from
> another, using the 'require' keyword. Use the word 'require', followed by
> the name of the file you want to include. you only need the prefix of the
> file, (you leave off the .rb part) and you surround the name with single
> quotes.
>
> file1.rb
>
> class MyClass1
> def myfunc1
> puts "function1 called!"
> end
> end
>
> ----
> file2.rb
>
> require 'file1'
>
> a = MyClass1.new
> a.myfunc1
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rubyscript instead of javascript Damjan Rems Ruby 29 09-12-2009 12:30 AM
RubyScript (ASP) - getting server variables Tim Morgan Ruby 5 05-12-2006 09:11 PM
RubyScript dpersik@gmail.com Ruby 15 12-22-2005 10:51 PM
Stupid question: Making scripts python-scripts Jan Danielsson Python 8 07-22-2005 12:20 AM
RubyScript munges up Windows command line operation Philo Del Middleston Ruby 1 07-03-2003 07:12 PM



Advertisments