请问ruby中 <=>是什么意思?

Python021

请问ruby中 <=>是什么意思?,第1张

这是ruby里“宇宙飞船运算符”。

运算符的左边和右边相比较,左边小于右边返回负数,相等返回0,大时返回正数。

宇宙飞船运算符主要用于排序。对元素的大小进行判定。

这种脚本语言做大型计算,计算能力肯定是不太够的,一般都依赖于其它语言编写的高性能计算的库,比如python就有numpy/scipy/pandas/matplotlib等一系列库,这使得python比较适合进行大型科学计算,ruby也有相当的库sciruby,不过成熟度还不太够,sciruby官网上的说法是,这个库已经经过了测试,但是还没有经过实战的检验,在使用中要有可能会遇到bug的心理预期。原话如下:

Word to the wise: These gems have been tested, but are not battle-hardened. If you’re thinking of using NMatrix (or other SciRuby components) to write mission critical code, such as for a self-driving car or controlling an ARKYD 100 satellite, you should expect to encounter a few bugs — and be prepared for them.