[Rubinius-devel] My first patch (String#reverse)

Laurent Julliard laurent at moldus.org
Tue Jan 2 11:47:08 EST 2007


This is my first patch to the kernel classes. Feedback welcome.
Side question: is there a place in the directory structure of Rubinius 
where to lace test code for the kernel classes?

laurent

Index: kernel/string.rb
===================================================================
--- kernel/string.rb    (revision 287)
+++ kernel/string.rb    (working copy)
@@ -128,6 +128,23 @@
      return str.join("")
    end

+  def reverse
+    str = ""
+    i = @bytes - 1
+    while i >= 0
+      str << self[i,1]
+      i -= 1
+    end
+    return str
+  end
+
+  def reverse!
+    sd = self.reverse
+    @data = sd.data
+    @bytes = sd.size
+    return self
+  end
+
    def strip
      r = /\s*([^\s].*[^\s])\s*/m
      m = r.match(self)


More information about the Rubinius-devel mailing list