How do I view the Ruby method #lcm in the source code? -


i'm trying understand how #lcm works. belongs in integer class, seen on docs. i've looked @ ruby's github page don't know how navigate it.

thanks.

personally, prefer read rubinius's source code on reading yarv's. rubinius better structured, better factored, and, above all, of written in language ruby programmers know well, namely ruby:

def lcm(other)   raise typeerror, "expected integer got #{other.class}" unless other.kind_of?(integer)   if self.zero? or other.zero?     0   else     (self.div(self.gcd(other)) * other).abs   end end 

ironruby's source code structured, unfortunately no longer maintained:

[rubymethod("lcm")] public static object/*!*/ lcm(int self, int other) {     return lcm(self, other, signedgcd(self, other)); }  [rubymethod("lcm")] public static object/*!*/ lcm(biginteger/*!*/ self, biginteger/*!*/ other) {     return lcm(self, other, signedgcd(self, other)); }  [rubymethod("lcm")] public static object/*!*/ lcm(object/*!*/ self, object other) {     throw rubyexceptions.createtypeerror("not integer"); } 

my third choice jruby:

public irubyobject lcm(threadcontext context, irubyobject other) {     checkinteger(context, other);     return f_lcm(context, this, rubyrational.intvalue(context, other)); } 

which points this:

public static irubyobject f_lcm(threadcontext context, irubyobject x, irubyobject y) {     if (f_zero_p(context, x) || f_zero_p(context, y)) {         return rubyfixnum.zero(context.runtime);     }     return f_abs(context, f_mul(context, f_div(context, x, f_gcd(context, x, y)), y)); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -