Say I have a class like so
class Date
attr_accessor :day, :month, :year
end
And I create 3 records for it, and add each to an array.
class Date
attr_accessor :day, :month, :year
end
date = Date.new()
date.day = 31
date.month = 12
date.year = 2019
array = []
array << date
date = Date.new()
date.day = 30
date.month = 2
date.year = 2014
array << date
date = Date.new()
date.day = 23
date.month = 1
date.year = 2012
array << date
If I wanted puts date.day (or every attribute) from the third record/third element of the array specifically, how would I access it (if I want to print it, or access it from a different function/procedure when specific user input is required)? Something like puts array[2] obviously doesn't work.
Dateis a really bad choice as its already a part of the Ruby standard library.Dateisn't actually defined until you require it. There are several list of reserved words in Ruby but I guess the only real way to check for name collision is to search the docs.