ObjectSpace#each_object example issue

Chris White <[email protected]> Fri, 29 Jul 2011 12:16:55 -0700
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
The documentation for ObjectSpace#each_object has the following sample code=
:

=A0*=A0=A0=A0=A0 a =3D 102.7
=A0*=A0=A0=A0=A0 b =3D 95=A0=A0=A0=A0=A0=A0 # Won't be returned
=A0*=A0=A0=A0=A0 c =3D 12345678987654321
=A0*=A0=A0=A0=A0 count =3D ObjectSpace.each_object(Numeric) {|x| p x }
=A0*=A0=A0=A0=A0 puts "Total count: #{count}"
=A0*
=A0*=A0 <em>produces:</em>
=A0*
=A0*=A0=A0=A0=A0 12345678987654321
=A0*=A0=A0=A0=A0 102.7
=A0*=A0=A0=A0=A0 2.71828182845905
=A0*=A0=A0=A0=A0 3.14159265358979
=A0*=A0=A0=A0=A0 2.22044604925031e-16
=A0*=A0=A0=A0=A0 1.7976931348623157e+308
=A0*=A0=A0=A0=A0 2.2250738585072e-308
=A0*=A0=A0=A0=A0 Total count: 7

In this case=2C c=2C with the value of 12345678987654321 is supposed to sho=
w for being a Bignum. However on 64 bit systems this isn't the case:

=3D 64bit MacOSX Ruby SVN HEAD =3D
irb(main):001:0> puts RUBY_VERSION + " " + RUBY_PLATFORM + " " + RUBY_PATCH=
LEVEL.to_s
1.9.2 x86_64-darwin10.8.0 290
=3D> nil
irb(main):002:0> 12345678987654321.class
=3D> Fixnum

This won't show because as explained=2C "Immediate objects (Fixnums=2C Symb=
ols true=2C false=2C and nil) are never returned." One a 32 bit system=2C h=
owever=2C this isn't an issue:

=3D 32bit Ubuntu Ruby SVN HEAD
irb(main):001:0> puts RUBY_VERSION + " " + RUBY_PLATFORM + " " + RUBY_PATCH=
LEVEL.to_s
1.9.4 i686-linux -1
=3D> nil
irb(main):002:0> 12345678987654321.class
=3D> Bignum

I see two possible solutions to this:

1) Use a number that produces Bignum on both 32 an 64 bit systems:

irb(main):003:0> 12345678987654321094903903903.class
=3D> Bignum

2) Split out the explanation to show 32 and 64 bit side by side?

3) Just add a side not explaining the issue with 32 and 64 bit differences

Also there might be another potential fix if there is some constant that ho=
lds the min and max values Bignum is capable of=2C but that's more of a fea=
ture request than a change in the docs.

- Chris
Twitter: @cwgem
 		 	   		  =