diff options
| author | taiyoslime <[email protected]> | 2020-10-05 19:53:05 +0900 |
|---|---|---|
| committer | taiyoslime <[email protected]> | 2020-10-13 14:09:36 +0900 |
| commit | bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54 (patch) | |
| tree | 166195f4009b90a90d1fe1b28ad4c8c84ba2597d /mrbgems/mruby-string-ext/mrblib/string.rb | |
| parent | 9ea7b718683386d2dc0787e919fc3d413ab20e67 (diff) | |
| download | mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.tar.gz mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.zip | |
Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <[email protected]>
Co-Authored-By: smallkirby <[email protected]>
Diffstat (limited to 'mrbgems/mruby-string-ext/mrblib/string.rb')
| -rw-r--r-- | mrbgems/mruby-string-ext/mrblib/string.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb index e57d75355..32914d074 100644 --- a/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -444,4 +444,27 @@ class String end self end + + def __upto_endless(&block) + return to_enum(:__upto_endless) unless block + + len = self.length + # both edges are all digits + bi = self.to_i(10) + if bi > 0 or bi == "0"*len + while true + s = bi.to_s + s = s.rjust(len, "0") if s.length < len + yield s + bi += 1 + end + return self + end + bs = self + while true + yield bs + bs = bs.succ + end + self + end end |
