def self.model
if RbConfig::CONFIG['host_os'] =~ /darwin/i
ptr = FFI::MemoryPointer.new(:long)
size = FFI::MemoryPointer.new(:size_t)
size.write_long(ptr.size)
if sysctlbyname("hw.cputype", ptr, size, nil, 0) < 0
raise "sysctlbyname function failed"
end
case ptr.read_long
when CPU_TYPE_X86, CPU_TYPE_X86_64
"Intel"
when CPU_TYPE_SPARC
"Sparc"
when CPU_TYPE_POWERPC, CPU_TYPE_POWERPC64
"PowerPC"
else
"Unknown"
end
else
if respond_to?(:sysctl, true)
buf = 0.chr * 64
mib = FFI::MemoryPointer.new(:int, 2)
size = FFI::MemoryPointer.new(:long, 1)
mib.write_array_of_int([CTL_HW, HW_MODEL])
size.write_int(buf.size)
if sysctl(mib, 2, buf, size, nil, 0) < 0
raise Error, "sysctl function failed"
end
buf.strip
else
pinfo = ProcInfo.new
if processor_info(0, pinfo) < 0
if processor_info(1, pinfo) < 0
raise Error, "process_info function failed"
end
end
pinfo[:pi_processor_type].to_s
end
end
end