diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /web/server/h2o/libh2o/deps/mruby/mrblib/range.rb | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz netdata-58daab21cd043e1dc37024a7f99b396788372918.zip |
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/server/h2o/libh2o/deps/mruby/mrblib/range.rb')
-rw-r--r-- | web/server/h2o/libh2o/deps/mruby/mrblib/range.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb new file mode 100644 index 000000000..5bd2521e8 --- /dev/null +++ b/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb @@ -0,0 +1,67 @@ +## +# Range +# +# ISO 15.2.14 +class Range + + ## + # Calls the given block for each element of +self+ + # and pass the respective element. + # + # ISO 15.2.14.4.4 + def each(&block) + return to_enum :each unless block + + val = self.first + last = self.last + + if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special + lim = last + lim += 1 unless exclude_end? + i = val + while i < lim + block.call(i) + i += 1 + end + return self + end + + if val.kind_of?(String) && last.kind_of?(String) # fixnums are special + if val.respond_to? :upto + return val.upto(last, exclude_end?, &block) + else + str_each = true + end + end + + raise TypeError, "can't iterate" unless val.respond_to? :succ + + return self if (val <=> last) > 0 + + while (val <=> last) < 0 + block.call(val) + val = val.succ + if str_each + break if val.size > last.size + end + end + + block.call(val) if !exclude_end? && (val <=> last) == 0 + self + end + + # redefine #hash 15.3.1.3.15 + def hash + h = first.hash ^ last.hash + h += 1 if self.exclude_end? + h + end +end + +## +# Range is enumerable +# +# ISO 15.2.14.3 +class Range + include Enumerable +end |