[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Class-level readers and writers

Christoph R.

11/30/2003 5:01:00 PM

David A. Black wrote:
...
> What you're describing is a similarity, not a connection :-)

I am not in the position to argue about fine point of the English
language with you, but a similarity is a "kind_of" (in the OO
sense) a connection in my orthographically challenged book:-)

> What I mean is that there's no interdependency, conceptually
> or in implementation, between class vars and class instance
> vars. People look for connections in trying to understand
> them, but they're actually best understood separately.

Maybe you right about the latter point - I just don't know ...

>
> As for the new-style class variables compares with
> traditional accessors defined on the Class object: the main
> difference I see is that the accessors are presumably
> callable by anyone, whereas the new class vars will be
> class-local (including instance method definitions). It's

You can can achieve the same effect by declaring the
class accessor methods (the instance version) protected

class A
__var__ = nil
protected
define_method(:var) {|| __var__ }
define_method(:var=) {|rhs| __var__= rhs }
...
end

Also I would not mind the introduction of ``class_protected''
visibility attribute for class methods. Of course, it is bit of a
contradiction to champion an extra access modifier in order
to simplify visibility rules:-)

Example: Given declaration

class A; end
class B < A
def self.meth
puts "okay"
end
class_protected :meth
end

class B
def m
B.meth
end
End

class A
def foo
B.meth
end
end


B.new.foo # okay
A.new.foo # NoMethodError - called class protected ...

...

/Christoph