开发者

Ruby Integer and Fixnum unexpexted behavior

开发者 https://www.devze.com 2022-12-24 09:47 出处:网络
I want to use gcd function of the Integer clas开发者_StackOverflows. Using the example from Ruby Doc as a test it fails:

I want to use gcd function of the Integer clas开发者_StackOverflows. Using the example from Ruby Doc as a test it fails:

irb(main):001:0> 72.gcd 168
NoMethodError: undefined method `gcd' for 72:Fixnum
        from (irb):1

I have the windows one click installer ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]. On other PCs with the same version of ruby this works correctly.

Any ideas?


Try

require 'rubygems'
72.gcd 168


require 'rational'

0

精彩评论

暂无评论...
验证码 换一张
取 消