Difference between revisions of "Text File Writer Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with "=Code To Implement= ==open_yield_close== {{RubyToImplement|text_file_writer|text_file_writer|TextFileWriter|Object|open_yield_close(path)}} =Client= <nowiki> TextFileWriter...")
 
Line 1: Line 1:
 +
=Background=
 +
==Ensure==
 +
https://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/ensure.html
 +
 +
note: this page covers the try/finally equivalent in Ruby and happens to use opening and closing a file as an example.
 +
 
=Code To Implement=
 
=Code To Implement=
 
==open_yield_close==
 
==open_yield_close==

Revision as of 17:38, 25 April 2022

Background

Ensure

https://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/ensure.html

note: this page covers the try/finally equivalent in Ruby and happens to use opening and closing a file as an example.

Code To Implement

open_yield_close

file: src/main/ruby/text_file_writer/text_file_writer.rb Ruby logo.svg
class: TextFileWriter
superclass: Object
methods: open_yield_close(path)

Client

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