Question: Question:
How do you create a class that can be used without using new
like Post.all
like ActiveRecord?
For example, by defining something for a class called Person
,
Person('yoshida').age
I am thinking about how to use it.
Also, is there something like the name of this? Instanceless class.
Answer: Answer:
Create a class method instead of an instance method.
class Post
def self.all
[1,2,3]
end
end
p Post.all