Possible Duplicate:
What does ||= mean in Ruby?
class Person
attr_accessor :name
class << self
attr_accessor :instances
def instances
@instances ||= []
@instances
end
end
def initialize( name )
Person.instances << self
@name = name
end
end
joe = Person.new( "Joe" )
zach = Person.new( "Zach" )
puts "You have #{Person.instances.size} people in existance!" POINT C
class Paramedic < Person
def initialize( name )
super( name )
Paramedic.instances << self
end
end
sally = Paramedic.new( "Sally" )
puts "You have #{Person.instances.size} people in existance!" #POINT B
puts "You have #{Paramedic.instances.size} paramedics in existance!" POINT C
What do these lines do?
@instances ||= []
Person.instances << self
Paramedic.instances << self