On Jan 14, 2010, at 6:12 PM, I=F1aki Baz Castillo wrote:

> Hi, is there a reliable way under Ruby to know the OS architecture =20
> (32 or 64
> bits)?
>
> I've just found RUBY_PLATFORM constant which returns "x86_64-linux" =20=

> under 64
> bits, however it doesn't send very reliable for me.
>
> I need a way working under Linux and BSD. Thanks for any suggestion.
>
> --=20
> I=F1aki Baz Castillo <ibc / aliax.net>
>


You can use Fixnum#size to get number of bytes for a Fixnum and =20
multiply by 8 bits/byte:

irb(main):001:0> 1.size * 8
=3D> 64
irb(main):002:0> RUBY_PLATFORM
=3D> "x86_64-linux"

irb> 1.size * 8
=3D> 32
irb> RUBY_PLATFORM
=3D> "universal-darwin9.0"

I think it's reliable. (Although I guess there could be a 32-bit ruby =20=

running on a 64-bit platform.)

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com