# PBI - mashing up RGL and method\_missing

**URL:** <https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955>\
**Category:** Ruby\
**Created:** [August 22, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955 "2006-08-22T17:20:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [August 22, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955/1 "2006-08-22T17:20:37Z")

</div>

Ruby Graph Language (RGL) allows graphical structures  
to be modeled as collections of objects. So, you can  
ask a node to iterate through its neighbors, etc.

I’ve been toying with ways to extend this notion, using  
(say) method\_missing. Here’s a hand-waving example,  
where “you” are assumed to be a Ruby object:

Let’s say that I want to find out how many of your  
neighbors have cats. Although you don’t know the  
answer, you do know who your neighbors are. They,  
in turn, know whether they have cats. So, I send  
you the following message:

```
count_neighbors_with_cats

```

Having no method of this name, you hand it off to  
method\_missing for parsing and such. As a result,  
each of your neighbors is sent a message such as:

```
have_cats?

```

After they respond, you tally and return the results.

Obviously, this could be done without method\_missing.  
For example, I could send you a Ruby script to eval.  
Alternatively, I could send you a YAML (or whatever)  
description. Each approach has its own flexibility,  
overhead, dangers, etc.

Has anyone done anything like this? I’d love to see  
pointers to related work, etc.

## -r

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [August 22, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955/2 "2006-08-22T22:45:52Z")

</div>

In article \<p06230914c110cc8d3bb9@[192.168.254.205]\>,  
Rich M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> answer, you do know who your neighbors are. They,
> 
> After they respond, you tally and return the results.
> 
> Obviously, this could be done without method\_missing.  
> For example, I could send you a Ruby script to eval.  
> Alternatively, I could send you a YAML (or whatever)  
> description. Each approach has its own flexibility,  
> overhead, dangers, etc.
> 
> Has anyone done anything like this? I’d love to see  
> pointers to related work, etc.

I guess I’d be inclined to do it like:

count\_neighbors(:have\_cats?)

and not use method\_missing for this. method\_missing is really quite  
nice,  
but if you over-use it it can be very difficult to debug.

Phil

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [August 22, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955/3 "2006-08-22T23:29:57Z")

</div>

At 5:45 AM +0900 8/23/06, Phil T. wrote:

> I guess I’d be inclined to do it like:
> 
> count\_neighbors(:have\_cats?)
> 
> and not use method\_missing for this.  
> method\_missing is really quite nice,  
> but if you over-use it, it can be very  
> difficult to debug.

Why do I believe this? 🙂

Anyway, it looks like you’re suggesting that I  
ask the node to run the count\_neighbors method,  
asking each of the neighbors to run :have\_cats?

This is vaguely along the lines of one approach  
I’ve been considering, where I would send only  
method names, in some hierarchical arrangement,  
to be executed by the appropriate objects.

If the methods don’t have side effects, it could  
be a bit like functional programming. Also, by  
restricting the availability of methods, I might  
be able to achieve a sort of “sandbox” effect.

Speaking of which, is there a (reasonable) way to  
limit the methods that are available within, say,  
an eval?

## -r

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [August 23, 2006, 2:16am UTC](https://www.ruby-forum.com/t/pbi-mashing-up-rgl-and-method-missing/65955/4 "2006-08-23T02:16:16Z")

</div>

In article \<p0623091cc111234e90db@[192.168.254.205]\>,  
Rich M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Why do I believe this? 🙂  
> Yes, it definitely can be difficult to debug programs which make heavy  
> use  
> of method\_missing (even light use in some cases 😉

> Anyway, it looks like you’re suggesting that I  
> ask the node to run the count\_neighbors method,  
> asking each of the neighbors to run :have\_cats?

right.

> Speaking of which, is there a (reasonable) way to  
> limit the methods that are available within, say,  
> an eval?

Maybe playing with $SAFE ?

You might also want to look into \_why’s Sandbox.

Phil
