In exactly the same way as I showed in the last post, but with a different method name.
First, it createshould return something using the method empty?. For instance:
class MyClass
def self.create
[]
end
end
If you want to work with instances MyClassaccording to your last question:
class MyClass
def self.create
MyClass.new
end
def initialize
@arr = []
end
def empty?
@arr.empty?
end
def add x
@arr << x
self
end
end
It MyClassacts like a simple wrapper around an array, providing a method add.
pry(main)> MyClass.create.empty?
=> true