Trans
4/4/2008 4:07:00 PM
On Apr 4, 11:38 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Apr 4, 2008, at 9:27 AM, Trans wrote:
>
> > Right it does. But it's not a "pollution" we are unaccustomed to --it
> > is merely constant lookup. So we can conceive of these as Constant
> > Methods.
>
> > However, you make a point. In having these it would probably require
> > we enforce that normal methods can not be capitalized. But, as Robert
> > says, they are rarely used. In fact, I would argue that when they are
> > used it is probably alwasy to achieve exactly the kind of
> > functionality this change would support.
>
> it's more complicated than that:
>
> module M
>
> def Clobber
> end
>
> Const = 42
>
> def self.included other
>
> :nothing
>
> end
>
> end
>
> class C
>
> include M
>
> end
>
> if you want method lookup to behave like constant lookup this would
> *have* to inject the Clobber method into C. this is not widely
> appreciated, but ruby injects the constants from a module into a class
> on inclusion *regardless* of any 'self.included' hook defined. so to
> maintain consistency between methods and constants we'd have to either
>
> A) have the above code cherry-pick caps methods and include them
> silently behind our backs
>
> B) Not have constants injected during module inclusion
Hmmm... I don't think that's right. These choices assume the viewpoint
that these are methods first, but rather I say they ought to be
constants first.
To give you better idea of what I mean, your example made me think of:
module M
Clobber = lambda {}
Const = 42
def self.included other
:nothing
end
end
class C
include M
end
Which is essentially the functionality desired, with the one exception
that the same name could be used for a class/module constant and a
method constant -- the () would differentiate which is meant.
T.