A
aidy
Hi,
I have assigned the current date to an instance variable and attempted
to use an attribute reader.
This is the code:
class Dates
attr_reader :current_date
def setCurrentDate
@current_date = Time.now.localtime.strftime("%d/%m/%Y")
end
end
I instantiate this and try to read the current date
d = Dates.new.current_date
p d
nil is returned (twice)
Although, if I do this
p Dates.new.setCurrentDate
I get two current dates, but I am not breaking Object rules?
I have also tried a traditional getter method with the same result.
Thank You
Aidy
I have assigned the current date to an instance variable and attempted
to use an attribute reader.
This is the code:
class Dates
attr_reader :current_date
def setCurrentDate
@current_date = Time.now.localtime.strftime("%d/%m/%Y")
end
end
I instantiate this and try to read the current date
d = Dates.new.current_date
p d
nil is returned (twice)
Although, if I do this
p Dates.new.setCurrentDate
I get two current dates, but I am not breaking Object rules?
I have also tried a traditional getter method with the same result.
Thank You
Aidy