[macruby-changes] [2259] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 7 14:13:48 PDT 2009


Revision: 2259
          http://trac.macosforge.org/projects/ruby/changeset/2259
Author:   mattaimonetti at gmail.com
Date:     2009-08-07 14:13:48 -0700 (Fri, 07 Aug 2009)
Log Message:
-----------
added #puts to StringIO

Modified Paths:
--------------
    MacRuby/trunk/lib/stringio.rb

Added Paths:
-----------
    MacRuby/trunk/spec/frozen/library/stringio/puts_tags.txt

Modified: MacRuby/trunk/lib/stringio.rb
===================================================================
--- MacRuby/trunk/lib/stringio.rb	2009-08-07 21:13:46 UTC (rev 2258)
+++ MacRuby/trunk/lib/stringio.rb	2009-08-07 21:13:48 UTC (rev 2259)
@@ -17,8 +17,8 @@
   # <code>$.</code> is updated only on the next read. 
   #
   attr_accessor :lineno
-  include Enumerable
   
+  include Enumerable  
   
   #    StringIO.open(string=""[, mode]) {|strio| ...}
   #
@@ -527,6 +527,48 @@
     end
     # send back what was passed, not our :to_int version
     len 
+  end
+  
+  #   strio.puts(obj, ...)    -> nil
+  #
+  #  Writes the given objects to <em>ios</em> as with
+  #  <code>IO#print</code>. Writes a record separator (typically a
+  #  newline) after any that do not already end with a newline sequence.
+  #  If called with an array argument, writes each element on a new line.
+  #  If called without arguments, outputs a single record separator.
+  #
+  #     io.puts("this", "is", "a", "test")
+  #
+  #  <em>produces:</em>
+  #
+  #     this
+  #     is
+  #     a
+  #     test
+  #
+  def puts(*args)
+    if args.empty?
+      write("\n")
+    else
+      args.each do |arg|
+        if arg == nil
+          line = "nil"
+        else
+          begin
+            arg = arg.to_ary
+            arg.each {|a| puts a }
+            next
+          rescue
+            line = arg.to_s
+          end
+        end 
+        
+        write(line)
+        write("\n") if !line.empty? && (line[-1] != ?\n)
+      end
+    end
+    
+    nil
   end           
 
 

Added: MacRuby/trunk/spec/frozen/library/stringio/puts_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/library/stringio/puts_tags.txt	                        (rev 0)
+++ MacRuby/trunk/spec/frozen/library/stringio/puts_tags.txt	2009-08-07 21:13:48 UTC (rev 2259)
@@ -0,0 +1 @@
+fails:StringIO#puts when passed [Array, ...] handles self-recursive arrays correctly
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090807/1f78ada4/attachment.html>


More information about the macruby-changes mailing list