# Neewby question: how to monitor a variable value

**URL:** <https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979>\
**Category:** Ruby\
**Created:** [October 20, 2006, 12:43pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979 "2006-10-20T12:43:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 20, 2006, 12:43pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/1 "2006-10-20T12:43:01Z")

</div>

Hello All,

I remember reading in a book that we could very easily monitor the  
value of a variable and have for instance an alert message displayed  
each time this variable s modified. I do not manage to find how to do  
this anymore.  
Would you have any clues ?

Thanks a lot,  
Luc

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 20, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/2 "2006-10-20T13:37:25Z")

</div>

On 20/10/06, Luc J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello All,
> 
> I remember reading in a book that we could very easily monitor the  
> value of a variable and have for instance an alert message displayed  
> each time this variable s modified. I do not manage to find how to do  
> this anymore.  
> Would you have any clues ?
> 
> Thanks a lot,  
> Luc

Sounds like you need the observer design pattern:  
[http://wiki.rubygarden.org/Ruby/page/show/ObserverPattern](http://wiki.rubygarden.org/Ruby/page/show/ObserverPattern)

Farrel

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 20, 2006, 4:10pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/3 "2006-10-20T16:10:31Z")

</div>

Luc J. wrote:

> I remember reading in a book that we could very easily monitor the  
> value of a variable and have for instance an alert message displayed  
> each time this variable s modified. I do not manage to find how to do  
> this anymore.

While I’m sure many other similar libraries exist, I’d like to offer up  
my own EventTarget library. Instead of being tied to a single event  
like the Observable pattern, you can register different callbacks for  
different types of actions that occur.

[http://phrogz.net/RubyLibs/rdoc/files/EventTarget\_rb.html](http://phrogz.net/RubyLibs/rdoc/files/EventTarget_rb.html)

One of these days I’ll get around to learning how to gem up my libs.  
Until then, you can download the source code from the link on that page.

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 20, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/4 "2006-10-20T16:31:58Z")

</div>

Thanks a lot gavin,  
I will also give it a try.

Luc

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 21, 2006, 12:43am UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/5 "2006-10-21T00:43:51Z")

</div>

> One of these days I’ll get around to learning how to gem up my libs.  
> Until then, you can download the source code from the link on that page.

I just got back from reading this on Ruby Inside and though I’d give  
you a heads up:

[http://www.rubyinside.com/generate-your-own-ruby-gems-more-easily-268.html](http://www.rubyinside.com/generate-your-own-ruby-gems-more-easily-268.html)

Charles

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 29, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/6 "2006-10-29T15:28:37Z")

</div>

Thanks a lot Farrel,  
This is exactly what I needed !!!  
Luc

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [October 21, 2006, 12:01am UTC](https://www.ruby-forum.com/t/neewby-question-how-to-monitor-a-variable-value/72979/7 "2006-10-21T00:01:45Z")

</div>

Luc J. wrote:

> Hello All,
> 
> I remember reading in a book that we could very easily monitor the  
> value of a variable and have for instance an alert message displayed  
> each time this variable s modified. I do not manage to find how to do  
> this anymore.  
> Would you have any clues ?

See also [http://raa.ruby-lang.org/project/observable](http://raa.ruby-lang.org/project/observable). (And see the  
example in my post a few minutes ago on the thread “[ANN] Dependency  
1.0.0”.)
