From f1a9be1ab7e8819e46789534ee16cd388e1ecf9f Mon Sep 17 00:00:00 2001 From: Michal Bugno Date: Sat, 7 Apr 2012 21:56:27 +0200 Subject: [PATCH] IO::write added --- kernel/common/io19.rb | 8 ++++++++ spec/tags/19/ruby/core/io/write_tags.txt | 5 ----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/common/io19.rb b/kernel/common/io19.rb index bda0ececb6..7f12aa2027 100644 --- a/kernel/common/io19.rb +++ b/kernel/common/io19.rb @@ -32,6 +32,14 @@ def self.binwrite(file, string, offset=nil) end end + def self.write(file, string, offset=nil) + mode = (offset.nil? || !File.file?(file)) ? "w:ASCII-8BIT" : "r+:ASCII-8BIT" + File.open(file, mode) do |f| + f.seek(offset || 0) + f.write(string) + end + end + def self.for_fd(fd, mode=undefined, options=undefined) new fd, mode, options end diff --git a/spec/tags/19/ruby/core/io/write_tags.txt b/spec/tags/19/ruby/core/io/write_tags.txt index 6843b9d24a..cc1b0d843e 100644 --- a/spec/tags/19/ruby/core/io/write_tags.txt +++ b/spec/tags/19/ruby/core/io/write_tags.txt @@ -1,8 +1,3 @@ -fails:IO.write coerces the argument to a string using to_s -fails:IO.write returns the number of bytes written -fails:IO.write creates a file if missing -fails:IO.write truncates the file and writes the given string -fails:IO.write doesn't truncate the file and writes the given string if an offset is given fails:IO.write accepts a :mode option fails:IO.write raises an error if readonly mode is specified fails:IO.write uses encoding from given options, if provided