[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Using object methods of first module in methods of second module

Nikita Petrov

4/5/2008 12:33:00 PM

Beforehand sorry for my English, I'm from Russia.

I have 2 modules:

module SendMail
def self.send_mail(hash)
# some code
end
end

module ActionMailer
def quoted_printable(text, charset)
# some code
end
end

Please say me, is there any way to have access to method
"quoted_printable" of module ActionMailer from method send_mail of
module SendMail. It would be good, if I pass using Classes in this
situation, because I want to divide
namespaces correctly.

2 Answers

Pit Capitain

4/6/2008 7:59:00 PM

0

2008/4/5, Nikita Petrov <nixikanius@gmail.com>:
> I have 2 modules:
>
> module SendMail
> def self.send_mail(hash)
> # some code
> end
> end
>
> module ActionMailer
> def quoted_printable(text, charset)
> # some code
> end
> end
>
> Please say me, is there any way to have access to method
> "quoted_printable" of module ActionMailer from method send_mail of
> module SendMail. It would be good, if I pass using Classes in this
> situation, because I want to divide
> namespaces correctly.

Nikita, quoted_printable is an instance method. So you need to have an
instance of a class which includes the ActionMailer module. If you
have such an instance, you can call its quoted_printable method.

Regards,
Pit

Gary Wright

4/6/2008 8:49:00 PM

0


On Apr 6, 2008, at 3:59 PM, Pit Capitain wrote:
> 2008/4/5, Nikita Petrov <nixikanius@gmail.com>:
>> I have 2 modules:
>>
>> module SendMail
>> def self.send_mail(hash)
>> # some code
>> end
>> end
>>
>> module ActionMailer
>> def quoted_printable(text, charset)
>> # some code
>> end
>> end
>>
>> Please say me, is there any way to have access to method
>> "quoted_printable" of module ActionMailer from method send_mail of
>> module SendMail. It would be good, if I pass using Classes in this
>> situation, because I want to divide
>> namespaces correctly.
>
> Nikita, quoted_printable is an instance method. So you need to have an
> instance of a class which includes the ActionMailer module. If you
> have such an instance, you can call its quoted_printable method.

If you want the object to be the SendMail module itself then extend
SendMail with ActionMailer:


module ActionMailer
def quoted_printable(text, charset)
# some code
end
end

module SendMail
extend ActionMailer
def self.send_mail(hash)
# some code
quoted_printable(....)
end
end