What is the meaning of method class in the class definition in Ruby?

Posted by Steven Xu on Stack Overflow See other posts from Stack Overflow or by Steven Xu
Published on 2011-01-06T05:30:55Z Indexed on 2011/01/06 5:54 UTC
Read the original article Hit count: 201

Filed under:
|

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)?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby