What is the meaning of method class in the class definition in Ruby?
- by Steven Xu
I'm familiar with function definitions and variable declarations being in class definitions:
public class MyClass {
public int myvar;
public void doSomething() {
}
}
But what does it "mean" in Ruby when a method is actually called in the class definition? This happens amply in Rails, for instance:
class User < ActiveRecord::Base
has_many :posts
end
What exactly does this do (at a lower level than "it adds some methods to the class")? How would I implement such a function (e.g., one that mixes in some additional methods)?