# Delegate and unless for \_\_

**URL:** <https://www.ruby-forum.com/t/delegate-and-unless-for/167249>\
**Category:** Ruby\
**Created:** [May 5, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249 "2009-05-05T22:50:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [May 5, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249/1 "2009-05-05T22:50:49Z")

</div>

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 =\> :@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](http://m.onkey.org/2008/10/5/sanity)

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [May 6, 2009, 6:41pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249/2 "2009-05-06T18:41:40Z")

</div>

On 05.05.2009 22:50, Raj S. wrote:

> 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

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [May 6, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249/3 "2009-05-06T19:15:06Z")

</div>

On Wed, May 6, 2009 at 6:40 PM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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** ”).  
> 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

–  
Si tu veux construire un bateau …  
Ne rassemble pas des hommes pour aller chercher du bois, préparer des  
outils, répartir les tâches, alléger le travail… mais enseigne aux  
gens la nostalgie de l’infini de la mer.

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

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [May 6, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249/4 "2009-05-06T21:01:31Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [May 6, 2009, 11:16pm UTC](https://www.ruby-forum.com/t/delegate-and-unless-for/167249/5 "2009-05-06T23:16:56Z")

</div>

On Wed, May 6, 2009 at 9:01 PM, Raj S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://www.ruby-forum.com/).

–  
Si tu veux construire un bateau …  
Ne rassemble pas des hommes pour aller chercher du bois, préparer des  
outils, répartir les tâches, alléger le travail… mais enseigne aux  
gens la nostalgie de l’infini de la mer.

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