[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Invoking a Method

Parv G.

12/5/2006 5:49:00 PM

Hi,
Newbie Question:

How do i invoke a method in belonging to a module?

For Example:
###############
#file: SampleModule.rb

Module SampleModule

def add(a, b)
return a + b
end

def multiply(a, b)
return a * b
end

end

################
#file: test.rb

require 'SampleModule.rb'
#here i would like to make a call to add() method of Module SampleModule
(sitting in file: SampleModule.rb)
help??

--
Posted via http://www.ruby-....

2 Answers

Parv G.

12/5/2006 5:53:00 PM

0

this seems to work:
SampleModule::add(2, 3)
so i think i'm ok for now.

Thanks.


--
Posted via http://www.ruby-....

James Gray

12/5/2006 5:56:00 PM

0

On Dec 5, 2006, at 11:48 AM, Parv G. wrote:

> Hi,
> Newbie Question:
>
> How do i invoke a method in belonging to a module?
>
> For Example:
> ###############
> #file: SampleModule.rb
>
> Module SampleModule

module_function

> def add(a, b)
> return a + b
> end
>
> def multiply(a, b)
> return a * b
> end
>
> end
>
> ################
> #file: test.rb
>
> require 'SampleModule.rb'
> #here i would like to make a call to add() method of Module
> SampleModule
> (sitting in file: SampleModule.rb)
> help??

SampleModule.add(1, 2)

Hope that helps.

James Edward Gray II