Difference between revisions of "Text File Writer Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 9: Line 9:
  
 
=Code To Implement=
 
=Code To Implement=
==open_yield_close==
+
==TextFileUtils==
{{RubyToImplement|text_file_writer|text_file_writer|TextFileWriter|Object|open_yield_close(path)}}
+
{{RubyToImplement|text_file_utils|text_file_utils|TextFileUtils|Object|write_text(path)}}
 +
==write_text(path)==
  
 
=Client=
 
=Client=

Revision as of 05:10, 25 November 2022

Background

Ensure

Ruby provides begin/rescue/ensure which is rather analogous to try/catch/finally in Java.

note: although coincidental, it is rather fitting that this reference covers begin/rescue/ensure with ensuring to close an opened file as its example. Ensuring to close an opened file is the canonical example for this sort of feature.

Yield

yield

Code To Implement

TextFileUtils

file: src/main/ruby/text_file_utils/text_file_utils.rb Ruby logo.svg
class: TextFileUtils
superclass: Object
methods: write_text(path)

write_text(path)

Client

  TextFileWriter.open_yield_close(path) do |file|
    file.write("<html><body><h1>#{Time.now}</h1></body></html>")
  end