From: "Mauricio Fernández" Date: 2003-03-27T17:43:03+09:00 Subject: Re: Conditionally make a method private? On Thu, Mar 27, 2003 at 10:50:44AM +0900, Jeremy wrote: > dblack@superlink.net wrote: > Actually, if I understand what you are saying, this is EXACTLY what I want. > What I was trying to accomplish was having an attribute that wasn't quite > global, but more accessable than just a normal class attribute. I do want But in a way it *is* global, as there's only one class attribute, it is simply scoped into that class. Every pair of database/menu objects will be using the same attribute. If all you want is to share some part of the internal state, you can simply externalize it as a separate object and keep as many references as needed. > M1's view of the status to change when I change it in M2. I think that the > best way to think of it is like this: > > I have two classes (a database class, and a menu class) that are different > enough that it doesn't warrant doing inheritance from a single superclass, > but I need any instances of the two classes to communicate directly. I > didn't really want to muck up global space with an attribute, because I > don't want all things to be able to access it. But I also didn't want to > do a lot of hardcoding in each class to make them "aware" of each other. I > wanted this to kind of act like a community whiteboard. Also, I needed > something that could possibly "do more", such as formatting, or automatic > message clearing, or things like that. Using the above code was about the > best that I could come up with for such a beast. As stated in the message > to John Johnson, the reasoning for the original posting was to see if I > could have some of them to act only as senders of messages (the databases), > and some as readers of messages (the menus). I still would like to do > something like that, but that will take a bit more thinking for me yet. > I'm still fresh meat in the ruby community, only having been using it for > about 3 weeks now. Now all this about writers and readers reminds me the Databus being used by Freeride. In believe it probably what you want (esp. the "act like a community whiteboard" part :) http://www.rubyide.org/cgi-bin/wiki.pl?Databus "The FreeBASE Databus is the internal mechanism through which plugins communicate with each other. It is a hierarchical publish/subscribe system that combines the features of a data repository and a messaging system. [...] The Databus uses a publish/subscribe mechanism that allows you to use the Databus as a messaging system. You can subscribe to any slot in the Databus to receive notifications whenever that slot changes." -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com People are going to scream bloody murder about that. -- Seen on linux-kernel