IO and rdoc Venkat Subramaniam svenkatcs uh edu
IO and rdoc Venkat Subramaniam – svenkat@cs. uh. edu 1
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 Venkat Subramaniam – svenkat@cs. uh. edu 2
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 Venkat Subramaniam – svenkat@cs. uh. edu 3
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 Venkat Subramaniam – svenkat@cs. uh. edu 4
Running all tests Venkat Subramaniam – svenkat@cs. uh. edu 5
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 Venkat Subramaniam – svenkat@cs. uh. edu 6
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: , : notnew: , : call-seq: , : include: , … • RDoc: : usage is useful to pick up usage comments for programs Venkat Subramaniam – svenkat@cs. uh. edu 7
rdoc example Venkat Subramaniam – svenkat@cs. uh. edu 8
rdoc output Venkat Subramaniam – svenkat@cs. uh. edu 9
- Slides: 9