开发者

Are there more accurate terms for "class methods" in Ruby?

开发者 https://www.devze.com 2023-02-04 08:22 出处:网络
Is there really such开发者_StackOverflow a thing as a \"class method\" in Ruby (which is sometimes regarded as the equivalent of a static method in other languages), or is it merely something that jus

Is there really such开发者_StackOverflow a thing as a "class method" in Ruby (which is sometimes regarded as the equivalent of a static method in other languages), or is it merely something that just happens to be a singleton method of an object of class Class?

If the latter, are there any more accurate terms for such methods that would still be understandable by the average Ruby developer?


"Class method" is the correct term.

See http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/ for a good explanation.


"Class method" is fine and will be well understood, but technically you are correct, it is simply an instance method defined on a Class instance (or one of its ancestors, potentially its singleton class).

0

精彩评论

暂无评论...
验证码 换一张
取 消