Eric Hodel wrote: > On 19 Jan 2005, at 09:46, Robert Klemme wrote: > >> >> "Eric Hodel" <drbrain / segment7.net> schrieb im Newsbeitrag >> news:12DE17DB-69B1-11D9-AFB0-000D93436DA0 / segment7.net... >> >> Looks like the simple var check is better performance wise. Personally I >> never felt the need for defined? - only during my initial Ruby stages, >> when I carried some Perl thinking with me; but never after I got rid of >> that. :-) > > > module M > def functionality > do_stuff if @x > end > end > > class C > include M > end > > C.new.functionality > > With ruby -w, this will give an 'uninitialized instance variable' > warning. M#functionality needs to be written this way to get rid of the > warning: > > module M > def functionality > @x = default unless defined? @x > do_stuff if @x > end > end What about @x ||= "default" ? :-) Although @x = default unless defined? @x looks much more readable :)