Ruby Programming/Reference/Objects/Time
Appearance
classTuesdaysattr_accessor:time,:placedefinitialize(time,place)@time=time@place=placeendendfeb12=Tuesdays.new("8:00","Rice U.")
As for the object, it is clever let me give you some advice though. Firstly, you don't ever want to store a date or time as a string. This is always a mistake. -- though for learning purposes it works out, as in your example. In real life, simply not so. Lastly, you created a class called Tuesdays without specifying what would make it different from a class called Wednesday; that is to say the purpose is nebulous: there is nothing special about Tuesdays to a computer. If you have to use comments to differentiate Tuesdays from Wednesdays you typically fail.
classEventdefinitialize(place,time=Time.new)@place=placecasetime.class.to_swhen"Array"@time=Time.gm(*time)when"Time"@time=timeelsethrow"invalid time type"endendattr_accessor:time,:placeend## Event at 5:00PM 2-2-2009 CSTfunStart=Event.new("evan-hodgson day",[0,0,17,2,2,2009,2,nil,false,"CST"])## Event now, (see time=Time.new -- the default in constructor)rightNow=Event.new("NOW!");## You can compaire Event#time to any Time object!!ifTime.new>funStart.timeputs"We're there"elseputs"Not yet"end## Because the constructor takes two forms of time, you can do## Event.new( "Right now", Time.gm(stuff here) )