[macruby-changes] [2258] MacRuby/trunk/lib/stringio.rb
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 7 14:13:47 PDT 2009
Revision: 2258
http://trac.macosforge.org/projects/ruby/changeset/2258
Author: mattaimonetti at gmail.com
Date: 2009-08-07 14:13:46 -0700 (Fri, 07 Aug 2009)
Log Message:
-----------
added truncate
Modified Paths:
--------------
MacRuby/trunk/lib/stringio.rb
Modified: MacRuby/trunk/lib/stringio.rb
===================================================================
--- MacRuby/trunk/lib/stringio.rb 2009-08-07 20:25:26 UTC (rev 2257)
+++ MacRuby/trunk/lib/stringio.rb 2009-08-07 21:13:46 UTC (rev 2258)
@@ -508,8 +508,26 @@
def close_write
raise(IOError, "closing non-duplex IO for writing") unless @writable
@writable = false
- end
-
+ end
+
+ # strio.truncate(integer) -> 0
+ #
+ # Truncates the buffer string to at most _integer_ bytes. The *strio*
+ # must be opened for writing.
+ #
+ def truncate(len)
+ raise(IOError, "closing non-duplex IO for writing") unless @writable
+ raise(TypeError) unless len.respond_to?(:to_int)
+ length = len.to_int
+ raise(Errno::EINVAL, "negative length") if (length < 0)
+ if length < string.size
+ @string[length .. string.size] = ""
+ else
+ @string = string.ljust(length, "\000")
+ end
+ # send back what was passed, not our :to_int version
+ len
+ end
protected
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090807/f92533d5/attachment.html>
More information about the macruby-changes
mailing list