summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/mrblib/string.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-06-16 11:35:42 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-06-16 11:35:42 +0900
commita7770a39aa4d59fd4fc973b42b9faa2a2b1cbd73 (patch)
tree726022fb5872384eaf0a3003d99ab9b346cc9f9c /mrbgems/mruby-string-ext/mrblib/string.rb
parentd4d99dd6d7e1374af3e567b175035b36977337c4 (diff)
parent4d9ca27ba6d44e7df56c02e240cc8795933072e5 (diff)
downloadmruby-a7770a39aa4d59fd4fc973b42b9faa2a2b1cbd73.tar.gz
mruby-a7770a39aa4d59fd4fc973b42b9faa2a2b1cbd73.zip
Merge branch 'string-upto' of https://github.com/ksss/mruby into ksss-string-upto
Diffstat (limited to 'mrbgems/mruby-string-ext/mrblib/string.rb')
-rw-r--r--mrbgems/mruby-string-ext/mrblib/string.rb44
1 files changed, 0 insertions, 44 deletions
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb
index 15f0549f3..c3a7eb380 100644
--- a/mrbgems/mruby-string-ext/mrblib/string.rb
+++ b/mrbgems/mruby-string-ext/mrblib/string.rb
@@ -305,50 +305,6 @@ class String
padding + self
end
- # str.upto(other_str, exclusive=false) {|s| block } -> str
- # str.upto(other_str, exclusive=false) -> an_enumerator
- #
- # Iterates through successive values, starting at <i>str</i> and
- # ending at <i>other_str</i> inclusive, passing each value in turn to
- # the block. The <code>String#succ</code> method is used to generate
- # each value. If optional second argument exclusive is omitted or is false,
- # the last value will be included; otherwise it will be excluded.
- #
- # If no block is given, an enumerator is returned instead.
- #
- # "a8".upto("b6") {|s| print s, ' ' }
- # for s in "a8".."b6"
- # print s, ' '
- # end
- #
- # <em>produces:</em>
- #
- # a8 a9 b0 b1 b2 b3 b4 b5 b6
- # a8 a9 b0 b1 b2 b3 b4 b5 b6
- #
- # If <i>str</i> and <i>other_str</i> contains only ascii numeric characters,
- # both are recognized as decimal numbers. In addition, the width of
- # string (e.g. leading zeros) is handled appropriately.
- #
- # "9".upto("11").to_a #=> ["9", "10", "11"]
- # "25".upto("5").to_a #=> []
- # "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"]
- #
- def upto(other_str, excl=false, &block)
- return to_enum :upto, other_str, excl unless block
-
- str = self
- n = self.<=>other_str
- return self if n > 0 || (self == other_str && excl)
- while true
- block.call(str)
- return self if !excl && str == other_str
- str = str.succ
- return self if excl && str == other_str
- return self if str.size > other_str.size
- end
- end
-
def chars(&block)
if block_given?
self.split('').each do |i|