Incorrect Ruby Integer and Fixnum Behavior

I want to use the gcd function for the Integer class. Using the Ruby Doc example as a test, it fails:

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

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

Any ideas?

+4
source share
2 answers

Try

 require 'rubygems' 72.gcd 168 
+2
source

require 'rational'

+2
source

Source: https://habr.com/ru/post/1304451/


All Articles