From: David Naseby Date: 2004-01-31T07:54:24+09:00 Subject: Re: Accesing to private attributes > -----Original Message----- > From: Imobach Gonz�lez Sosa [mailto:imodev@softhome.net] > I was discusing about Object Oriented Languages with a friend and > I have a > question to do. Well, using Python, you can access to a private > member of a > class just prepending an underscore and the class name (i.e.: > _myClass__myAttribute). It doesn't sound good to me. I don't like private > attributes being accesible from outside. > > So, I'd like to know if you can do it on Ruby. I think no, that > you must to > use a method, but I'm in doubt. Ruby doesn't really get in your way if you need to do something like this. It does, however, give you alarming looking keywords and syntax, so yo at least see the code is smelly: class AA; def initialize; @a = 1; end; end aa = AA.new aa.instance_eval { puts @a; @a = 2 } aa.instance_variable_set :@a, 17 aa.instance_variable_get :@a David http://homepages.ihug.com.au/~naseby/