Friday, January 5, 2007

Ruby's RI documentation

Ruby's RI program recognize '::' as class method and '#' or '.' as instance method File::dirname means dirname is class method of class File File#stat means stat is instance method of class File. So to get document of class method dirname of the class File, we type
huy@huy-desktop:~/support$ri File::dirname
we will get something like that
---------------------------------------------------------- File::dirname
     File.dirname(file_name ) -> dir_name
------------------------------------------------------------------------
     Returns all components of the filename given in _file_name_ except
     the last one. The filename must be formed using forward slashes
     (``+/+'') regardless of the separator used on the local file
     system.

        File.dirname("/home/gumby/work/ruby.rb")   #=> "/home/gumby/work"
To to get document of instance method stat of the class File, we type
huy@huy-desktop:~/support$ri File#stat
or other way is
huy@huy-desktop:~/support$ri File.stat
the result then is
------------------------------------------------------------- File#lstat
     file.lstat   =>  stat
------------------------------------------------------------------------
     Same as +IO#stat+, but does not follow the last symbolic link.
     Instead, reports on the link itself.

        File.symlink("testfile", "link2test")   #=> 0
        File.stat("testfile").size              #=> 66
        f = File.new("link2test")
        f.lstat.size                            #=> 8
        f.stat.size                             #=> 66

No comments: