How to create a class that can be instantiated in Ruby without using new

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 ,


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

p Post.all
Scroll to Top