the12 the12 - 1 month ago 9
Ruby Question

In Ruby, what is are the specific methods to retrieve the return value of Class.new (an instance)?

Given the following code below:

class Animal
end

dog = Animal.new # --> return value of Animal.new


What are the specific methods to retrieve the return value for Animal.new? I understand that a new instance is created from the class Animal and assigned to the variable dog. But what are the methods to retrieve the return value of Animal.new?

Answer

According to docs here:

new(args, ...) → obj

Calls allocate to create a new object of class’s class, then invokes that object’s initialize method, passing it args. This is the method that ends up getting called whenever an object is constructed using .new.