I\'ve been coding in Ruby for sometime now, but I don\'t understand when to use:
def self.METHOD_NAME
end
or just:
def METH
In this context - def self.method_name makes it sort of equivalent to the Java static method:
ruby:
class HexHelper
def self.to_h(num)
sprintf("%x", num)
end
end
use: HexHelper.to_h(12345)
java:
public class HexHelper
{
public static String toHex(int num)
{
return new PrintfFormat("%x").sprintf(num);
}
}
use: HexHelper.toHex(12345)