From eeca6ec8f511933e9a403e6b6166b874eead25b1 Mon Sep 17 00:00:00 2001 From: ksss Date: Wed, 4 Jan 2017 14:00:28 +0900 Subject: Rewrite String#prepend with Ruby Fix #3357 --- mrbgems/mruby-string-ext/mrblib/string.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mrbgems/mruby-string-ext/mrblib/string.rb') diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb index e6fbe7ddc..6e5f3c73d 100644 --- a/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -385,4 +385,18 @@ class String end end alias each_codepoint codepoints + + ## + # call-seq: + # str.prepend(other_str) -> str + # + # Prepend---Prepend the given string to str. + # + # a = "world" + # a.prepend("hello ") #=> "hello world" + # a #=> "hello world" + def prepend(arg) + self[0, 0] = arg + self + end end -- cgit v1.2.3