I believe this is fundamental to my understanding of Ruby and object-oriented programming in general, so I am asking this rather simplified question here, at the risk of looking stupid. I practiced with irb. I created my first class:
$ irb ruby-1.9.2-p290 :001 > class Person ruby-1.9.2-p290 :002?> attr_accessor :firstname, :lastname, :gender ruby-1.9.2-p290 :003?> end => nil ruby-1.9.2-p290 :004 > person_instance = Person.new => #<Person:0x007f9b7a9a0f70> ruby-1.9.2-p290 :005 > person_instance.firstname = "Bob" => "Bob" ruby-1.9.2-p290 :006 > person_instance.lastname = "Dylan" => "Dylan" ruby-1.9.2-p290 :007 > person_instance.gender = "male" => "male"
So Person.new
is my object, right? Or is my object a combination of class Person
and the attributes that I defined for this class?
source share