90 likes | 253 Views
IO and rdoc. File IO. File.new(filename, “r”) The mode may be r - read only w - write only r+ - read/write w+ - read/write; truncates file a - write/append a+ - read/append b - used with above modes, indicates binary mode. Using File. File.new nees a close
E N D
File IO • File.new(filename, “r”) • The mode may be • r - read only • w - write only • r+ - read/write • w+ - read/write; truncates file • a - write/append • a+ - read/append • b - used with above modes, indicates binary mode
Using File • File.new nees a close • Make sure you put the close in ensure block to ensure it is closed • Alternately, you may use the open method • Open a file • You can work with it in the closure • closes automatically when you return from closure • safe since close is called in ensure
Reading File • You may use gets or use one of the convenience methods • each_line by default uses \n as delimiter, you may specify some other character as well • IO.foreach may also be used
rdoc • Ruby documentation generator • like javadoc, ndoc, … • Produces html and ri documentation • Picks up comments before interesting elements like classes, methods,… • Picks up comments in # or between =being rdoc and =end • Comments between #-- and #++ are ignored • -word- or <em> multi words</em> for italics • *word* or <b> multi words</b> for bold • +word+ or <tt> multi words</tt> for typewriter
rdoc presentation • Hyperlinks • Picks up as links the Class names, method names, elements preceded by #,… • http, www, … • Lists created using * or 1. or a. • =, ==, … for headings • --- for hr • Doc modifiers control what gets generated • :yield:, :nodoc:, :doc:, :notnew:, :call-seq:, :include:, … • RDoc::usage is useful to pick up usage comments for programs