From: Pit Capitain Date: 2007-02-14T23:40:42+09:00 Subject: Re: Initializing dynamic instance methods Lars Olsson schrieb: > What's the best way to remedy the error/warning that the following > code produces? > > class Parent > def self.foo() > module_eval("def foo(); @foo; end") > module_eval("def foo=(newfoo); @foo = newfoo; end") > end > end > > class Child < Parent > foo > end > > c = Child.new > p c.foo > > (running with ruby -w) > (eval):1: warning: instance variable @foo not initialized > nil I don't know if its the best way, but you could try module_eval("def foo(); @foo if defined? @foo; end") Regards, Pit