Class: Archimate::MaybeIO

Inherits:
Object
  • Object
show all
Defined in:
lib/archimate/maybe_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) {|the| ... } ⇒ MaybeIO

Creates a MaybeIO object passing it yielding it to the given block

Examples:

Usage

Archimate::MaybeIO.new(myfile) do |io|
  io.write("Writing away")
end

Parameters:

  • filename (String, nil)

    determines the IO yielded to the given block String: filename to make writable IO for nil: - A fake IO

Yield Parameters:

  • the (IO)

    given block gets an IO (or fake IO)



19
20
21
22
23
24
25
26
27
# File 'lib/archimate/maybe_io.rb', line 19

def initialize(filename)
  if filename.nil?
    yield self
  else
    File.open(filename, "w") do |io|
      yield io
    end
  end
end

Instance Method Details

#write(_str) ⇒ Object

Implementation of the NilIO write method - effectively passes the input String to /dev/null

Parameters:

  • _str (String)
    • unused, no effect



33
# File 'lib/archimate/maybe_io.rb', line 33

def write(_str); end