delegate and unless for __

Discussion in 'Ruby' started by Raj Singh, May 5, 2009.

  1. Raj Singh

    Raj Singh Guest

    Anytime I see the delegate code usually there is an unless along with
    it. The code might look like this.

    Object.instance_methods.each do |m|
    delegate m, :to => :mad:model unless m =~ /^__/
    end


    I am thinking that __ is escaped so that one could called
    object.__SEND__ and this call will not be sent to the delegate. Is that
    the reason why __ is not delegated to the delegate or the actual
    reasoning is something else?

    That piece of code as picked up from http://m.onkey.org/2008/10/5/sanity
    --
    Posted via http://www.ruby-forum.com/.
    Raj Singh, May 5, 2009
    #1
    1. Advertising

  2. On 05.05.2009 22:50, Raj Singh wrote:
    > Anytime I see the delegate code usually there is an unless along with
    > it. The code might look like this.
    >
    > Object.instance_methods.each do |m|
    > delegate m, :to => :mad:model unless m =~ /^__/
    > end
    >
    >
    > I am thinking that __ is escaped so that one could called
    > object.__SEND__ and this call will not be sent to the delegate. Is that
    > the reason why __ is not delegated to the delegate or the actual
    > reasoning is something else?


    I think you're spot on. There seems to be a convention that method
    whose names start with underscores are not really meant to be part of
    the regular public interface (such as "__send__").

    Kind regards

    robert
    Robert Klemme, May 6, 2009
    #2
    1. Advertising

  3. Raj Singh

    Robert Dober Guest

    On Wed, May 6, 2009 at 6:40 PM, Robert Klemme
    <> wrote:
    > On 05.05.2009 22:50, Raj Singh wrote:
    >>
    >> Anytime I see the delegate code usually there is an unless along with
    >> it. The code might look like this.
    >>
    >> Object.instance_methods.each do |m|
    >> =A0delegate m, :to =3D> :mad:model unless m =3D~ /^__/
    >> end
    >>
    >>
    >> I am thinking that __ is escaped so that one could called
    >> object.__SEND__ and this call will not be sent to the delegate. Is that
    >> the reason why __ is not delegated to the delegate or the actual
    >> reasoning is something else?

    >
    > I think you're spot on. =A0There seems to be a convention that method who=

    se
    > names start with underscores are not really meant to be part of the regul=

    ar
    > public interface (such as "__send__").

    So do I think :)
    However, unless this is a somehow contrived example, I would love to
    know more about the usecase for this.
    Delegating all Object methods somehow puzzles me. Please do not get me
    wrong, there might be a very good reason for this. But I am curious,
    because whenever I did something like this I rather deleted the
    methods, mixed in something or extended objects.
    Maybe delegation was something I should have considered even in core
    related metaprogramming.
    Would you care to elaborate?

    Thx in advance
    Robert

    --=20
    Si tu veux construire un bateau ...
    Ne rassemble pas des hommes pour aller chercher du bois, pr=E9parer des
    outils, r=E9partir les t=E2ches, all=E9ger le travail=85 mais enseigne aux
    gens la nostalgie de l=92infini de la mer.

    If you want to build a ship, don=92t herd people together to collect
    wood and don=92t assign them tasks and work, but rather teach them to
    long for the endless immensity of the sea.

    --
    Antoine de Saint-Exup=E9ry
    Robert Dober, May 6, 2009
    #3
  4. Raj Singh

    Raj Singh Guest

    Hi Robert,

    Thanks for the answer.

    As I posted in the question the code is picked up from
    http://m.onkey.org/2008/10/5/sanity . I did not code it so I do not know
    the justification for this style of coding.

    I was just curious about leaving methods starting with __ as it is.
    --
    Posted via http://www.ruby-forum.com/.
    Raj Singh, May 6, 2009
    #4
  5. Raj Singh

    Robert Dober Guest

    On Wed, May 6, 2009 at 9:01 PM, Raj Singh <> wrote:
    > Hi Robert,
    > I was just curious about leaving methods starting with __ as it is.

    Than thank you even more for sharing the link :)
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >




    --=20
    Si tu veux construire un bateau ...
    Ne rassemble pas des hommes pour aller chercher du bois, pr=E9parer des
    outils, r=E9partir les t=E2ches, all=E9ger le travail=85 mais enseigne aux
    gens la nostalgie de l=92infini de la mer.

    If you want to build a ship, don=92t herd people together to collect
    wood and don=92t assign them tasks and work, but rather teach them to
    long for the endless immensity of the sea.

    --
    Antoine de Saint-Exup=E9ry
    Robert Dober, May 6, 2009
    #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. Irfan

    Delegate and Thread Problem

    Irfan, May 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,699
    Nick Harris
    May 6, 2004
  2. George K
    Replies:
    3
    Views:
    1,719
    John Saunders
    Nov 25, 2003
  3. =?Utf-8?B?TWluaCBLaG9h?=

    Please give me more information about delegate and its usage?

    =?Utf-8?B?TWluaCBLaG9h?=, Sep 27, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    908
    Kevin Spencer
    Sep 28, 2005
  4. Giovanni Azua
    Replies:
    0
    Views:
    424
    Giovanni Azua
    Nov 30, 2007
  5. Gábor SEBESTYÉN

    Unless unless

    Gábor SEBESTYÉN, Jun 17, 2005, in forum: Ruby
    Replies:
    3
    Views:
    150
    Gábor SEBESTYÉN
    Jun 17, 2005
Loading...

Share This Page