[suby-talk] Truly Private Methods
TRANS
transfire at gmail.com
Thu Sep 1 15:36:44 EDT 2005
On 9/1/05, Peter Vanbroekhoven <calamitas at advalvas.be> wrote:
> On Thu, 1 Sep 2005, TRANS wrote:
>
> > Thinking about your namespace idea and had a thought. Presently one
> > can define a "meta" method:
> >
> > class X
> > def self.x ; ... ; end
> > end
> >
> > Or as singleton on an object.
> >
> > o = Object.new
> > def o.x ; ... ; end
> >
> > I wonder if it can be extended to autovivify to a namspace if an
> > object of that name doesn't exist?
> >
> > class X
> > def o.x ; ... ; end
> > end
>
> Your example is a pretty bad one I guess because it creates a new object,
> defines a method for it, and leaves the object for the GC to snack on.
That don't sound so good :-( I didn't think it would leave the object
though, but I suppose(d) it would loose the reference to it after the
class closes.
> But I do think this would be possible, sure enough, although I don't see a
> clear link with namespaces, but I think that may be because we both may
> still have a different idea about them.
>
> > Also, does that mean a namespace is a class?
> >
> > class Namespace
> > initialize( obj )
> > self = obj # not possible but if
> > end
> > end
>
> Sure, there could be a Namespace class. Though maybe as with binding,
> instantiation can't be done explicitly. I'll have to think of that.
>
> But I'm not sure what the initialize above would do.
>
> Maybe I should put my ideas on namespaces on the wiki, see where it gets
> me, and see what you think about it. It seems to me that we are on a
> slightly different wavelength for the moment. Sometimes you go a bit
> faster than I can follow...
Sorry, more then likely I'm just confused. But you're right, I get a
head of myself even. It would be very great/helpful to see your ideas
about this on the wiki.
So, to slow down and clarify... I was thinking about your concept of
private and protected _named_ namespaces. I believe you wrote:
private:foo()
Where private was an explictly named namespace and foo of course the
method in it. Recall I was thinking about how classes/modules form a
kind of namespace and I created that example of using classes to
provide these private/protected namespaces. I was further thinking
about the metaclass/singleton-class in the same manner, and thought of
the shorthand used to define methods in their scope (def self.foo). So
I extrapolated from this to:
class X
ns = Namespace.new( self )
def ns.ameth
...
And then thought perhaps the ns could be autovivified.
Anyway, that was basically my train of thought. But probably I'm not
understanding something significant about namespaces --I get the
feeling I missing something. I just don't know what it is, so I don't
know how to ask about it :-(
T.
More information about the suby-talk
mailing list