iij/mrubyとmruby/mrubyとの差分解消 (mrblib編) #141

Closed
akiray03 opened this Issue Jun 25, 2013 · 0 comments

Projects

None yet

2 participants

diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index daa35c5..cffa498 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -89,6 +89,10 @@ class Integer
     end
     self
   end
+
+  def div(other)
+    self.divmod(other)[0]
+  end
 end

 ##
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 131d304..f286a54 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -133,6 +133,31 @@ class String
     a = self[pos+1..-1]
     self.replace([b, value, a].join(''))
   end
+
+  def %(args)
+    sprintf(self, *args)
+  end
+
+  def slice!(arg1, arg2 = 1)
+    return nil if arg2 < 0
+    if arg1.class == Fixnum
+      rval = self[arg1, arg2]
+      len = self.length
+      rpos = arg1 + arg2
+      rpos += len if arg1 < 0
+      rlen = len - rpos
+      region_l = self[0...arg1]
+      region_r = self[rpos, rlen]
+      region_r = '' if region_r == nil
+      self.replace(region_l + region_r)
+    elsif arg1.class == String
+      rval = arg1
+      self.gsub!(arg1, "")
+    else
+      return nil
+    end
+    rval
+  end
 end

 ##
@tsahara tsahara added the move label Mar 11, 2014
@tsahara tsahara closed this Mar 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment