Using object methods of first module in methods of second module

Discussion in 'Ruby' started by Nikita Petrov, Apr 5, 2008.

  1. 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.
     
    Nikita Petrov, Apr 5, 2008
    #1
    1. Advertising

  2. Nikita Petrov

    Pit Capitain Guest

    2008/4/5, Nikita Petrov <>:
    > 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
     
    Pit Capitain, Apr 6, 2008
    #2
    1. Advertising

  3. Nikita Petrov

    Gary Wright Guest

    On Apr 6, 2008, at 3:59 PM, Pit Capitain wrote:
    > 2008/4/5, Nikita Petrov <>:
    >> 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
     
    Gary Wright, Apr 6, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dirk Meusel
    Replies:
    1
    Views:
    3,030
    Dirk Meusel
    Aug 19, 2003
  2. bienwell
    Replies:
    4
    Views:
    3,866
    bienwell
    May 27, 2005
  3. -ecosys.com
    Replies:
    4
    Views:
    312
    Calvin Spealman
    Sep 28, 2007
  4. Stuart Redmann
    Replies:
    5
    Views:
    494
    Stuart Redmann
    Dec 14, 2007
  5. yelipolok
    Replies:
    4
    Views:
    273
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page