I am having some namespace issues. For example I have the following.
require 'net/smtp'
module Tim
module Net
def Net.send_email (to, subject, msg, from =
'timu...@gmail.com', smtpserver = Tim::Config.mail_server)
tostr = if to.is_a?(Array)
to.join(",")
elsif to.is_a?(String)
to
else
""
end
msg="To: #{tostr}\nFrom: #{from}\nSubject: #{subject}\n\n#{msg}"
Net::SMTP.start(smtpserver) do |smtp|
smtp.send_message( msg, from, to )
end
end #send email
end #module net
end #module Tim
This causes an error because the code thinks Net::SMTP should be in my
module. How do I refer to the SMTP in the Net library explicitly?
I have similar problems when I try to define Tim::Logger or something similar.
Thanks.
::Net::SMTP is what you're after.
> I have similar problems when I try to define Tim::Logger or something similar.
>
> Thanks.
>
> >
>
--
Cheers
Koz
I know. If you look at my code you'll see that I am trying to use
NET::SMTP from inside of my module Tim::Net.
You asked how to specify a Net module that's at the root not insude
Tim. You prefix it with those two colons :)
::Net::SMTP
--
Cheers
Koz
Ah sorry. I get it now.
>
> This is not a rails question per se but it's a ruby question.
>
> I am having some namespace issues. For example I have the following.
>
>
> This causes an error because the code thinks Net::SMTP should be in my
> module. How do I refer to the SMTP in the Net library explicitly?
You can access a top-level constant by using ::Net::SMTP.
Helpful?
Tim