Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Random idea - private, blocks, constants"
>     on Thu, 14 Dec 2006 05:25:11 +0900, "Daniel Berger" <djberg96 / gmail.com> writes:
>
> |What do people think of the idea of private (and protected) taking a
> |block?
> |
> |class Foo
> |   private do
> |      SOME_VALUE 88
> |      def some_method
> |          7
> |      end
> |   end
> |end
> |
> |This wouldn't really be any different than the current behavior for
> |methods, but it would (in theory) allow you to make constants, class
> |variables and class instance variables private.
> |
> |My main reason for wanting this behavior is that, in some cases, I
> |declare constant values that aren't meant for public use.
>
> Hmm, first we have to define how private constants (and class
> variables) behave.
>
> Class variables are not supposed to be accessed outside of a class
> body.  So they are always private, I guess.  We don't need special
> treatment for them.

True.

> But how should private constants behave?  Maybe
> making them not accessible via :: operator is suffice.  I'm not sure
> yet.

That seems reasonable, so long as you could still cheat, and get at
them via const_get if you wanted to (for testing purposes, for
example).  To me that would be roughly analogous to private methods
that are still accessible via send.

> The next thing I need to think about is how we can implement them.
> But it's another story.  As far as I can imagine now, it surely is
> difficult, since currently there's no place to save visibility
> information in the constants table.

I poked around in eval.c to see if I could come up with a patch on my
own, but I think it's beyond me.

Regards,

Dan