Sha256: a3a789f787939427c48d98a4fceb6e44e0c2e6e8c10742324202f7e823b1d6b5

Contents?: true

Size: 366 Bytes

Versions: 54

Compression:

Stored size: 366 Bytes

Contents

# if given a filename, writes to the file (and returns the filename),
# otherwise, writes to a string. Yields an io object to write to.
def write_file_or_string(filename=nil, &block)
  out = 
    if filename
      File.open(filename,'w')
    else
      StringIO.new
    end
  block.call(out)
  if filename
    out.close
    filename
  else
    out.string
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
mspire-0.10.8.0 lib/write_file_or_string.rb
mspire-0.10.7.3 lib/write_file_or_string.rb
mspire-0.10.7.2 lib/write_file_or_string.rb
mspire-0.10.7.1 lib/write_file_or_string.rb
mspire-0.10.7 lib/write_file_or_string.rb
mspire-0.10.6 lib/write_file_or_string.rb
mspire-0.10.5 lib/write_file_or_string.rb
mspire-0.10.4 lib/write_file_or_string.rb
mspire-0.10.3 lib/write_file_or_string.rb
mspire-0.10.2 lib/write_file_or_string.rb
mspire-0.10.1 lib/write_file_or_string.rb
mspire-0.10.0 lib/write_file_or_string.rb
mspire-0.9.2 lib/write_file_or_string.rb
mspire-0.9.1 lib/write_file_or_string.rb
mspire-0.9.0 lib/write_file_or_string.rb
mspire-0.8.7 lib/write_file_or_string.rb
mspire-0.8.6.2 lib/write_file_or_string.rb
mspire-0.8.6.1 lib/write_file_or_string.rb
mspire-0.8.6 lib/write_file_or_string.rb
mspire-0.8.5 lib/write_file_or_string.rb