From: "Shot (Piotr Szotkowski)" Date: 2010-01-20T18:44:00+09:00 Subject: Re: Looking for object.inherits?(Classname) --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert Klemme: > irb(main):010:0> a =3D [] > =3D> [] [=E2=80=A6] > irb(main):015:0> Enumerable =3D=3D=3D a > =3D> true > Note that I do not recommend using the test from line 12 as it is > likely much more inefficient than the other ones. The test from line > 15 is especially suited for use with "case" statements as in > case a > when Enumerable > puts "it's enumerable" > when Array, Hash > puts "It's a special enumerable" > when Integer > puts "You can count on me." > else > puts "No idea about a." > end A minor nitpick: Note that due to case=E2=80=99s behaviour (once a =E2=80= =98when=E2=80=99 matches, other =E2=80=98whens=E2=80=99 are ignored), the above will almost = never=C2=B9 print =E2=80=98It's a special enumerable=E2=80=99, as Arrays and Hashes are= almost always=C2=B9 Enumerable. Testing for Array/Hash first and Enumerable second would make more sense in most cases. =C2=B9 you can redefine any constant, so you could redefine what Array and Hash mean, but usually it=E2=80=99s a rather bad idea =E2=80=94 Shot --=20 You can write good programs in PHP, but the language does not support it. [Karol Kozub] --ikeVEW9yuYc//A+q Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAktW0FwACgkQi/mCfdEo8UqcAQCeJf3HFrgjB31RoyH8/dK8Tk/S YxMAn0cg8sLWmdN6kC8KKmM3tWNDgSSk =1sF4 -----END PGP SIGNATURE----- --ikeVEW9yuYc//A+q--