There are many other classes builtin into the Ruby interpreter, some of these are:
to manage directory and files, with functions as: chdir, pwd, exists?, mkdir, new, delete.
There are also some iterators on files.
Dir.pwd is the current directory.
to manage exceptions with methods: message , status, success? (true is status zero or nil)
to_s : a string representation of the message
represents files, with all the unix functions for files and more, as: atime, ctime, dirname, executable?, directory?, file? ,exists?, readable? ,zero?, truncate, delete, new, rename, ftype, lstat ,link, symlink, path, size, stat
for input/output and functions as: new, pipe, open, read, write, sync, eof?, and many iterators on the file content.
a semaphore for synchronization of accesses to resources
random numbers
A mini-class to contain strings which can be accessed by symbols:
Customer = Struct.new(:name, :surname) # => makes the Customer object c1=Customer.new("giovanni", "bianco") # makes instances c2=Customer.new("giovanna","rossi") c1.name => "giovanni" # using builtin accessors c1["name"] => "giovanni" c1.members=> [:name, :surname] # using symbols as accessors c1.to_a => ["giovanni", "bianco"] c1.to_h : make an hash ( only for Ruby 2 )
to manage threads , with function as fork, kill , new, stop.
class for time and date:
t = Time.at(0) => 1970-01-01 01:00:00 +0100 t1= Time.gm(2000,"jan",1,20,15,1) => 2000-01-01 20:15:01 UTC t2= Time.local(2000,"jan",1,20,15,1) => 2000-01-01 20:15:01 -0600 t3= Time.new(2010, 12, 25, 8, 0, 0, "-06:00") # => 2010-12-25 08:00:00 -0600 tn=Time.now => 2014-08-27 16:04:34 +0200 tn.getgm => 2014-08-27 14:06:40 UTC # convert from local to UTC Time.now.asctime => "Wed Aug 27 16:05:51 2014" # as an ASCII string tn.strftime(special string ) # formatted as in the printf function of C tn.strftime("today is %d/%m/%Y %H:%S") => "today is 27/08/2014 16:40" tn.to_a => [40, 6, 16, 27, 8, 2014, 3, 239, true, "CEST"] # as an array to_f ; to_i => giulian seconds from 1870 localtime ; gmtime ; => convert times in place
Parts of the data can be obtained by:
t = Time.at(0) t.min ; t.sec ; t.hour; t.hour ; t.day ; t.mon; t.year; t.zone ; t.wday ; t.mday; t.sec ; t.usec ; t. nsec => in julian seconds, microseconds, nanoseconds