What does a Java static method look like in Ruby?
Posted
by Hosh
on Stack Overflow
See other posts from Stack Overflow
or by Hosh
Published on 2010-03-17T05:25:55Z
Indexed on
2010/03/17
5:31 UTC
Read the original article
Hit count: 276
In Java, a 'static method' would look like this:
class MyUtils {
. . .
public static double mean(int[] p) {
int sum = 0; // sum of all the elements
for (int i=0; i<p.length; i++) {
sum += p[i];
}
return ((double)sum) / p.length;
}
. . .
}
// Called from outside the MyUtils class.
double meanAttendance = MyUtils.mean(attendance);
What's the equivalent 'Ruby way' of writing a 'static method'?
© Stack Overflow or respective owner