Skip to content

Commit

Permalink
IO::write added
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Bugno committed Apr 11, 2012
1 parent c9f5431 commit f1a9be1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 8 additions & 0 deletions kernel/common/io19.rb
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions 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
Expand Down

0 comments on commit f1a9be1

Please sign in to comment.