From: Yohanes Santoso Date: 2002-11-09T01:54:11+09:00 Subject: Re: Making Instace Variables Private/Local William Djaja Tjokroaminata writes: > If I am the project manager, I will enforce this to my subordinates: when > the class local variables are available, then everyone will use only class > local (private) variables, and child classes will access the parent's data > using methods, never the variables directly. In this way there is no risk Well, you could try the untested code below to privatise parent's instance variables. You'll need Wayne Conrad's stack frame patch: http://yagni.com/stack_frames/index.php class Module def attr_local(*args) args.each {|arg| if not arg.is_a? Symbol raise "attr_local is supplied with non-symbol arguments" end get_block = %q{def #{arg.to_s} if stack_frames[0].class.is_a? self raise "unauthorised access to local variable" else @#{arg.to_s} end} set_block = %q{def #{arg.to_s}=(value) if stack_frames[0].class.is_a? self raise "unauthorised access to local variable" else @#{arg.to_s} = value end} module_eval get_block module_eval set_block } end end But, really, humans (programmers) must bear some responsibility. The situation is like the interface. You can define interfaces, but those who implement them are not guaranteed to give the functionality you expect. Like (java): interface Consume { public void eat(); } class Human implements Consume { .... }; class IOStream implements Consume { ... }; Both classes implement two methods with the same name, but totally different behaviours. So, in the end it's still the programmers' responsibility to make things sensible. YS.