Sha256: 0a0188239dbe7b7bfe81f09079d32d64465f5f994c34030e60d52a6bfa6eccfc

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

#!/usr/local/bin/ruby -w

#
# == extensions/io.rb
#
# Adds methods to the builtin IO class.
#

require "extensions/_base"

# This is Ruby's built-in IO class.
class IO
end

#
# * IO.write
#
ExtensionsProject.implement(IO, :write, :class) do
  class << IO
    #
    # Writes the given data to the given path and closes the file.  This is
    # done in binary mode, complementing <tt>IO.read</tt> in standard Ruby.
    #
    # Returns the number of bytes written.
    #
    def write(path, data)
      File.open(path, "wb") do |file|
        return file.write(data)
      end
    end
  end
end

#
# * IO.writelines
#
ExtensionsProject.implement(IO, :writelines, :class) do
  class << IO
    #
    # Writes the given array of data to the given path and closes the file.
    # This is done in binary mode, complementing <tt>IO.readlines</tt> in
    # standard Ruby.
    #
    # Note that +readlines+ (the standard Ruby method) returns an array of lines
    # <em>with newlines intact</em>, whereas +writelines+ uses +puts+, and so
    # appends newlines if necessary.  In this small way, +readlines+ and
    # +writelines+ are not exact opposites. 
    #
    # Returns +nil+. 
    #
    def writelines(path, data)
      File.open(path, "wb") do |file|
        file.puts(data)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
extensions-0.5.0 lib/extensions/io.rb
extensions-0.6.0 lib/extensions/io.rb
glue-0.15.0 vendor/extensions/io.rb
glue-0.14.0 vendor/extensions/io.rb
glue-0.16.0 vendor/extensions/io.rb
glue-0.17.0 vendor/extensions/io.rb
nitro-0.11.0 vendor/extensions/io.rb
nitro-0.10.0 vendor/extensions/io.rb
nitro-0.12.0 vendor/extensions/io.rb
nitro-0.13.0 vendor/extensions/io.rb
nitro-0.9.5 vendor/extensions/io.rb
nitro-0.8.0 vendor/extensions/io.rb
nitro-0.9.3 vendor/extensions/io.rb
og-0.11.0 vendor/extensions/io.rb
og-0.10.0 vendor/extensions/io.rb
og-0.12.0 vendor/extensions/io.rb
og-0.8.0 vendor/extensions/io.rb
og-0.9.5 vendor/extensions/io.rb
og-0.9.3 vendor/extensions/io.rb