El Viernes, 15 de Enero de 2010, Walton Hoops escribió:
> On 1/15/2010 9:36 AM, Walton Hoops wrote:
> > On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
> >> Hi, is there a reliable way under Ruby to know the OS architecture
> >> (32 or 64
> >> bits)?
> >>
> >> I've just found RUBY_PLATFORM constant which returns "x86_64-linux"
> >> 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.
> >
> > I can't vouch for how accurate it is, but an OS gem was recently
> > announced on this list.
> > gem install os
> >
> > irb(main):001:0> require 'os'
> > => true
> > irb(main):002:0> OS.bits
> > => 64
> > irb(main):004:0> OS.posix?
> > => true
> > irb(main):005:0>
> 
> Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit
> system though.
> On my Windows 7 x64 (with 32-bit ruby):
> irb(main):005:0> OS.bits
> => 32
> irb(main):006:0> 1.size
> => 4
> irb(main):007:0>

Note that to know the bits it uses "rbconfig" gem, and them:

 def self.bits
    @bits ||= begin
      require 'rbconfig'
      host_os = RbConfig::CONFIG['host_os']
      if host_os =~ /32/
        32
      else
        if host_os =~ /64/
          64
        else # cygwin...
          if (1<<32).class == Fixnum
            64
          else
            32
          end
        end
      end
    end
  end


In my server RbConfig::CONFIG['host_os'] = "linux-gnu" so finally it ends 
doing:

          if (1<<32).class == Fixnum
            64
          else
            32
          end

Which is basically the same as doing

  if 1.size == 8
    64
  else
    32
  end



-- 
Iñaki Baz Castillo <ibc / aliax.net>