Re: ObjectSpace#each_object example issue
Roger Pack <[email protected]> Tue, 2 Aug 2011 14:28:49 -0600
| Newsgroups | gmane.comp.lang.ruby.documentation |
|---|---|
| Message-ID | <CAL1QdWcreGF8XRfj7itLg7br=g+wxYQYTW_E=LzsTFHtTLrNZA@mail.gmail.com> |
I'd probably just add a little note explaining the different ("this is
for 32 bit systems, for 64 bit it would...")
But that's just me.
Feel free to formulate a patch to the core and submit it for consideration:
http://blog.steveklabnik.com/2011/05/10/contributing-to-ruby-s-documentatio=
n.html
Cheers!
-roger-
On Fri, Jul 29, 2011 at 1:16 PM, Chris White <[email protected]> wrote:
>
> The documentation for ObjectSpace#each_object has the following sample co=
de:
>
> =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, c, with the value of 12345678987654321 is supposed to show =
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_PAT=
CHLEVEL.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, "Immediate objects (Fixnums, Symbol=
s true, false, and nil) are never returned." One a 32 bit system, however, =
this isn't an issue:
>
> =3D 32bit Ubuntu Ruby SVN HEAD
> irb(main):001:0> puts RUBY_VERSION + " " + RUBY_PLATFORM + " " + RUBY_PAT=
CHLEVEL.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 difference=
s
>
> Also there might be another potential fix if there is some constant that =
holds the min and max values Bignum is capable of, but that's more of a fea=
ture request than a change in the docs.
>
> - Chris
> Twitter: @cwgem
>
>