From: Tom Sawyer Date: 2002-08-12T13:59:29+09:00 Subject: Re: ambiguity between local variable assignment and writter method well, given that there dosen't seem a reasonable solution to the ambiguity between local var assignments and standard ruby setter methods, i am taking kent's advice, and from this day forward will use something i picked up from rich kilmer. no longer will i use #var= setter methods! i'm creating my own attribute module methods to replace attr_reader, attr_writer, and attr_accessor. instead of having a seperate method for assignment, i use the same method as the reader, but it checks to see if there's an argument passed. if there is than it acts like a setter. not positive about the names of these yet, but: class Module def Module.attr_rw(name) name = name.to_s class_eval <<-EOS if not method_defined?(:#{name}) def #{name}(*args) if args.length > 0 return @#{name} = args[0] else if @#{name} return @#{name} else return @#{name} = nil end end end end EOS end def Module.attr_ro(name) name = name.to_s class_eval <<-EOS if not method_defined?(:#{name}) def #{name} if @#{name} return @#{name} else return @#{name} = nil end end end EOS end end is this the right way to go about this? can anyone improve on this code? or see any flaws that need to be fixed? i don't have a write only version, do i really need it? i don't think i've have used one before. given all is well i can now do: class X attr_rw :instancevar def initialize instancevar 'i am me' # set puts instancevar # get end end -- ~transami