From: Xavier Noria Date: 2012-03-22T06:11:30+09:00 Subject: Re: What’s the best way to check if a feature/class has been loaded? --e89a8ff24c7b32464604bbc73c2a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Mar 21, 2012 at 9:51 PM, Nikolai Weibull wrote: There=E2=80=99s a timing issue with using const_defined? followed by const_= get > instead of calling const_get directly and catching NameError. What do you mean? The problem with const_get is that it follows the ancestors, of course, and you have no way around that in 1.8. I guess > > def feature?(path) > path.split('::').reduce(Object){ |o, e| > c =3D begin o.const_get(e); rescue NameError; return nil end > return nil if c =3D=3D (o !=3D Object and begin Object.const_get(e); > rescue NameError; nil end) > c > } > end Nikolai, I don't really understand what you need. You are askind for defined? X::Y that goes step by step and your original code does raise an error for X::Y integer. Then this second version cannot say that X::Y is defined in module X Y =3D nil end And you refuse to reuse much more simple and proven existing solutions. You want something with so special semantics that definitely is NOT built-in. That answers you original question. Good luck! --e89a8ff24c7b32464604bbc73c2a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Mar 21, 2012 at 9:51 PM, Nikolai Weibull <now@bitwi.se> w= rote:

I guess

def feature?(path)
=C2=A0 path.split('::').reduce(Object){ |o, e|
=C2=A0 =C2=A0 c =3D begin o.const_get(e); rescue NameError; return n= il end
=C2=A0 =C2=A0 return nil if c =3D=3D (o !=3D Object and begin Object.const= _get(e);
rescue NameError; nil end)
=C2=A0 =C2=A0 c
=C2=A0 }
end

Nikolai, I don't really understand = what you need. You are askind for defined? X::Y that goes step by step and = your original code does raise an error for X::Y integer.

Then this second version cannot say that X::Y is defined in

=C2=A0 =C2=A0 module X
=C2=A0 =C2=A0 = =C2=A0 Y =3D nil
=C2=A0 =C2=A0end

= And you refuse to reuse much more simple and proven existing solutions.

You want something with so special semantics that defin= itely is NOT built-in. That answers you original question.

Good luck!

--e89a8ff24c7b32464604bbc73c2a--