From: Peter Vandenabeele Date: 2012-02-14T19:52:44+09:00 Subject: [ruby-core:42611] Re: [ruby-trunk - Bug #6020] Unexpected is_a/kind_of behaviour --00235429d75cf103ef04b8ea64a2 Content-Type: text/plain; charset=UTF-8 On Tue, Feb 14, 2012 at 11:41 AM, Alex N wrote: > > Issue #6020 has been updated by Alex N. > > > =begin > well, at least (({Integer.is_a?(Integer) #=> true})). TL;DR : use `is_a?` on an _object_ of the class, not on the class itself. Long version: The confusion is that is_a? checks if the _object_ is of class Integer, not the Integer _class_. So. $ irb 1.9.3p0 :001 > i = 12 => 12 1.9.3p0 :002 > i.class => Fixnum i is an _object_ of the Fixnum class. 1.9.3p0 :003 > i.is_a?(Integer) => true yes, the _object_ i is an Integer ... 1.9.3p0 :004 > i.is_a?(Fixnum) => true ... and also a Fixnum 1.9.3p0 :005 > Integer.class => Class 1.9.3p0 :006 > Integer.is_a?(Integer) => false but the _class_ Integer is not an Integer (because Class does not inherit from Integer). 1.9.3p0 :007 > Class.ancestors => [Class, Module, Object, Wirble::Shortcuts, PP::ObjectMixin, Kernel, BasicObject] Class only inherits from Module, Object and BasicObject and mixes in some additional functionality. HTH, Peter -- *** Available for a new project *** Peter Vandenabeele http://twitter.com/peter_v http://rails.vandenabeele.com http://coderwall.com/peter_v --00235429d75cf103ef04b8ea64a2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Tue, Feb 14, 2012 at 11:41 AM, Alex N <masterlambaster= @gmail.com> wrote:

Issue #6020 has been updated by Alex N.


=3Dbegin
well, at least (({Integer.is_a?(Integer) #=3D> true})).


TL;DR : use `is_a?` on an _object_ of the class, not on the class = itself.

Long version:

The confusion is that is_a? checks if t= he _object_ is of class Integer,
not the Integer _class_.

So.

$ irb
1.9.3p0 :001 > i =3D= 12
=C2=A0=3D> 12
1.9.3p0 :002 > i.class
=C2=A0=3D> Fixn= um

i is an _object_ of the Fixnum class.

1.9.3p0 :003 > i= .is_a?(Integer)
=C2=A0=3D> true

yes, the _object_ i is an Integer ...

1.9= .3p0 :004 > i.is_a?(Fixnum)
=C2=A0=3D> true

... and also a= Fixnum

1.9.3p0 :005 > Integer.class
=C2=A0=3D> Class
1= .9.3p0 :006 > Integer.is_a?(Integer)
=C2=A0=3D> false

but the _class_ Integer is not an Integer
(b= ecause Class does not inherit from Integer).

1.9.3p0 :007 > Class= .ancestors
=C2=A0=3D> [Class, Module, Object, Wirble::Shortcuts, PP::= ObjectMixin, Kernel, BasicObject]

Class only inherits from Module, Object and BasicObject and mixes in so= me
additional functionality.

HTH,

Peter
<= /div>


--
*** Available for a new project ***

Peter Vandenabeele
http://twitter.com= /peter_v
http://rails.vandenabeele.com
http://coderwall.com/peter_v
--00235429d75cf103ef04b8ea64a2--