I tried the following but got an error ‘wrong number of arguments (2 for 0)’:
class Rating
NOOB = Rating.new(1, "U A NOOB")
def initialize(rating, message)
@rating = rating
@message = message
end
end
What would be the equivalent of writing the following in Ruby? (this is my way of doing enums)
public class Rating {
public static Rating NOOB = new Rating(1, "U SO NOOB");
public static Rating EXPERT = new Rating(2, "U A PRO BRO");
private int rating;
private String message;
public Rating(int rating, String message) {
this.rating = rating;
this.message = message;
}
...
}
It works if you put
below the definition of
initialize, as otherwise the interpreter hasn’t interpreted it, yet, and doesn’t know about the arguments it takes.