From: George Ogata Date: 2007-02-18T22:37:04+09:00 Subject: Re: Instance variable exists? Hi Detief, Aur, On 2/19/07, SonOfLilit wrote: > On 2/18/07, Detlef Reichl wrote: > > Hi, > > > > what is the preferred way to see if an object already includes a > > instance variable? > > > > for now i do something like: > > > > @my_object.instance_variables.include? "var_name" > > > Hi, > > AFAIK it's the only way. There's also: obj.instance_eval{defined?(@foo)} As you're hopefully aware, though, it's probably not particularly straightforward because it's discouraged in general. Peeking at an object's instance variables is kinda intruding on its privacy. There are some valid uses to be sure, but usually I think you're better off providing accessors for anything of interest outside the object. > Question: Why does Object#instance_varialbe_get have no documentation? > It's behaviour isn't that clear in cases like Where are you looking? "ri instance_variable_get" gives me docs. Regards, George.