Self.number_of_instances


#1

Can someone please explain how self.number_of_instances works? I don't recall learning this.

Thanks.


#2

I'm a beginner having the same question.
Here's what I found on http://ruby-doc.org/core-2.2.3/TracePoint.html#method-i-self

Self( )
Return the trace object during event
same as #binding:

Binding( )
Return the generated binding object from event

not totaly clear in my head, yet.


#3

self refers to the current class, when inside of it.

We're defining a method called number_of_instances, but which will be called from the class of the object, as demonstrated in the rest of the code:

puts "Number of Person instances: #{Person.number_of_instances}"