You have to generate your own Struct class subclass of Struct using Struct::new, which returns new Struct class.. Creates a new structure class containing members specified by mem.... St
Trang 1Stuct is a abstract class that collects named attributes bundled in an object You have to generate your own Struct class (subclass of Struct) using
Struct::new, which returns new Struct class
Example
S = Struct::new(:foo, :bar)
s = S::new(1,2)
s.foo # => 1
s.bar = 5 # update the member
s.bar # => 5
s # => #<S foo=1, bar=5>
Included Module
Enumerable
Class Method
Struct::new([ name,] mem )
Creates a new structure class containing members specified by mem
If name is given, the structure class is bound to the constant under Struct,
for example Struct::Passwd Note that Struct::new doesn't return
a structure object itself, but rather a class that is used as a template for
creating each structure
Structure Class Methods
S::members
Returns an array of member names
S::new( value )
Creates a new structure object value objects specify the initial value of
each member and must match the number of members specified when the structure was created
Instance Methods
s[ mem]
Trang 2Returns the value of member mem where mem is a symbol or integer If mem
is an integer, the value of the memth member is returned
s[ mem]= value
Sets the value of member mem mem may be a symbol or integer
s.each {| x| }
Calls block once for each member
s.members
Returns an array of member names
s.values
Returns an array containing the value of each member
Time is an object corresponding to a certain time Internally, it's stored as a number
of seconds since the epoch, 00:00:00, January 1, 1970 UTC Time class can
handle both a system's local time and UTC at the same time, but no other time zones can be handled
Included Module
Comparable
Class Methods
Time::at( time[, usec=0])
Creates a Time object time may be a Time object or an integer
representing the number of seconds elapsed since the epoch, 00:00:00,
January 1, 1970 UTC
Trang 3Time::gm( year[, month=1[, day=1[, hour=0[, min=0[, sec=0[, usec=0]]]]])
see
Time::utc(year[,month=1[,day=1[,hour=0[,min=0[,sec=
0 [,usec=]]]]]])
Time::local( year[, month=1[, day=1[, hour=0[, min=0[, sec=0 [, usec=0]]]]]]) Time::mktime( year[, month=1[, day=1[, hour=0[, min=0[, sec=0 [, usec=0]]]]]])
Creates a Time object interpreted in the local time zone
Time::new
Time::now
Creates a Time object expressing the current system time
Time::times
Returns a Tms structure containing user and system CPU times retrieved by the times system call Here are the Tms structure members:
utime
User CPU time
stime
System CPU time
cutime
CPU time elapsed for user child processes
cstime
CPU time elapsed for system child processes
Time::utc( year[, month=1[, day=1[, hour=0[,min=0[, sec=0 [, usec=0]]]]]])
Trang 4Time::gm( year[, month=1[, day=1[, hour=0[, min=0[, sec=0[, usec=0]]]]])
Creates a Time object interpreted as UTC (Coordinated Universal Time, formally known as GMT)
Instance Methods
t + n
Returns a Time object with n number of seconds added
t - x
If x is another Time object, the time difference is returned in seconds as a
Float If x is a number, a Time object with x number of seconds
subtracted is returned
t <=> other
t > other
t >= other
t < other
t <= other
Time comparisons
t.asctime
t.ctime
Returns t as a string
t.day
t.mday
Returns the day of the month (1-31) for t
t.gmtime
Trang 5See t.utc
t.gmtime?
See t.utc?
t.hour
Returns the hour of the day (0-23) for t
t.isdst
Returns true if t occurs during daylight saving time
t.localtime
Turns on representation mode of t to local time
t.min
Returns the minute of the hour (1-59) for t
t.mon
t.month
Returns the month of the year (1-12) for t
t.sec
Returns the second of the minute (1-60) for t There can be a 60th second of
the minute due to leap second
t.strftime( format)
Formats t according to formatting directives, which may be any of these:
%A Full weekday name (Sunday, Monday )
%a Abbreviated weekday name (Sun, Mon )
%B Full month name (January, February )