Friend functions or classes

Discussion in 'Ruby' started by SunRaySon, Dec 2, 2007.

  1. SunRaySon

    SunRaySon Guest

    Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    Hi,

    I would like to simulate something like friend class or method in Ruby; From
    the pickaxe documentation I could not figure out if there is one directly
    available or not.

    I do understand that having friend classes and functions is not good
    practice.

    Regards,
    Kiran.
    SunRaySon, Dec 2, 2007
    #1
    1. Advertising

  2. SunRaySon

    Dejan Dimic Guest

    On Dec 2, 11:02 am, SunRaySon <> wrote:
    > Note: parts of this message were removed by the gateway to make it a legal Usenet post.
    >
    > Hi,
    >
    > I would like to simulate something like friend class or method in Ruby; From
    > the pickaxe documentation I could not figure out if there is one directly
    > available or not.
    >
    > I do understand that having friend classes and functions is not good
    > practice.
    >
    > Regards,
    > Kiran.


    Friend Functions and Friend Classes are often useful for one class to
    see the private variables of another class, even though these
    variables should probably not be made part of the public interface
    that the class supports.

    Friend function or friend classes are one of most dangerous
    construction. From my experience mostly because programmers tend to
    misuse it. I do not want to make this an academic issue so to make
    this short: my advice is do not use friend class as a construction in
    you code especially if you try to port some C++ algorithm even if that
    seams to look like an easy thing to do.

    Depending on particular reason, why do you think you have to use the
    friend class, I will most probably consider using observer and/or
    visitor pattern in stand.
    Dejan Dimic, Dec 2, 2007
    #2
    1. Advertising

  3. SunRaySon

    Steckly, Ron Guest

    Scripting Outlook

    Hi All,

    I'm new to Ruby and I'm trying to script Microsoft Outlook to save
    attachments that exceed half a megabyte. I am using WIN32OLE, and
    trying to reference Outlook as a COM object. I also downloaded the OLE
    browser and am examining the different things I can call. My really
    rough, and inexperienced code,=20
    is:
    require 'win32ole'

    outlook=3DWIN32OLE.new('Outlook.Application')

    mapi =3Doutlook.GetNameSpace('MAPI')

    inbox=3Dmapi.GetDefaultFolder(6)

    indox.Items.each do |message|
    if message.Attachment.Size > 500,000
    message.Attachment.SaveAsFile('path to
    remote drive')
    end

    Any thoughts on this?

    Ron

    -----Original Message-----
    From: Dejan Dimic [mailto:]=20
    Sent: Sunday, December 02, 2007 12:35 PM
    To: ruby-talk ML
    Subject: Re: Friend functions or classes

    On Dec 2, 11:02 am, SunRaySon <> wrote:
    > Note: parts of this message were removed by the gateway to make it a

    legal Usenet post.
    >
    > Hi,
    >
    > I would like to simulate something like friend class or method in

    Ruby; From
    > the pickaxe documentation I could not figure out if there is one

    directly
    > available or not.
    >
    > I do understand that having friend classes and functions is not good
    > practice.
    >
    > Regards,
    > Kiran.


    Friend Functions and Friend Classes are often useful for one class to
    see the private variables of another class, even though these
    variables should probably not be made part of the public interface
    that the class supports.

    Friend function or friend classes are one of most dangerous
    construction. From my experience mostly because programmers tend to
    misuse it. I do not want to make this an academic issue so to make
    this short: my advice is do not use friend class as a construction in
    you code especially if you try to port some C++ algorithm even if that
    seams to look like an easy thing to do.

    Depending on particular reason, why do you think you have to use the
    friend class, I will most probably consider using observer and/or
    visitor pattern in stand.
    Steckly, Ron, Dec 2, 2007
    #3
  4. SunRaySon

    SunRaySon Guest

    Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    Thanks Dejan. I will try it out.

    Kiran.


    On Dec 2, 2007 11:05 PM, Dejan Dimic <> wrote:

    > On Dec 2, 11:02 am, SunRaySon <> wrote:
    > > Note: parts of this message were removed by the gateway to make it a

    > legal Usenet post.
    > >
    > > Hi,
    > >
    > > I would like to simulate something like friend class or method in Ruby;

    > From
    > > the pickaxe documentation I could not figure out if there is one

    > directly
    > > available or not.
    > >
    > > I do understand that having friend classes and functions is not good
    > > practice.
    > >
    > > Regards,
    > > Kiran.

    >
    > Friend Functions and Friend Classes are often useful for one class to
    > see the private variables of another class, even though these
    > variables should probably not be made part of the public interface
    > that the class supports.
    >
    > Friend function or friend classes are one of most dangerous
    > construction. From my experience mostly because programmers tend to
    > misuse it. I do not want to make this an academic issue so to make
    > this short: my advice is do not use friend class as a construction in
    > you code especially if you try to port some C++ algorithm even if that
    > seams to look like an easy thing to do.
    >
    > Depending on particular reason, why do you think you have to use the
    > friend class, I will most probably consider using observer and/or
    > visitor pattern in stand.
    >
    >
    SunRaySon, Dec 3, 2007
    #4
  5. SunRaySon

    Ilan Berci Guest


    >
    > Depending on particular reason, why do you think you have to use the
    > friend class, I will most probably consider using observer and/or
    > visitor pattern in stand.


    irb(main):001:0> class Foo
    irb(main):002:1> private
    irb(main):003:1> def cant_see_me
    irb(main):004:2> "ouch! found me"
    irb(main):005:2> end
    irb(main):006:1> end
    => nil
    irb(main):007:0> Foo.new.send('cant_see_me')
    => "ouch! found me"

    Walking down this path leads to the dark side, the power of the dark
    side is strong, you will have powers beyond your wildest imagination.
    --
    Posted via http://www.ruby-forum.com/.
    Ilan Berci, Dec 3, 2007
    #5
    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. Razvan
    Replies:
    11
    Views:
    898
    Andrew Thompson
    Jul 17, 2004
  2. Adam Parkin
    Replies:
    6
    Views:
    509
    Victor Bazarov
    Apr 24, 2004
  3. Jess
    Replies:
    1
    Views:
    272
    John Harrison
    May 20, 2007
  4. mojmir
    Replies:
    3
    Views:
    323
    mojmir
    Sep 12, 2008
  5. Peter
    Replies:
    2
    Views:
    267
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page