diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
commit | be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-proc-ext/mrblib | |
parent | Initial commit. (diff) | |
download | netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip |
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb b/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb new file mode 100644 index 00000000..b7166393 --- /dev/null +++ b/web/server/h2o/libh2o/deps/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb @@ -0,0 +1,42 @@ +class Proc + + def ===(*args) + call(*args) + end + + def yield(*args) + call(*args) + end + + def to_proc + self + end + + def curry(arity=self.arity) + type = :proc + abs = lambda {|a| a < 0 ? -a - 1 : a} + arity = abs[arity] + if lambda? + type = :lambda + self_arity = self.arity + if (self_arity >= 0 && arity != self_arity) || + (self_arity < 0 && abs[self_arity] > arity) + raise ArgumentError, "wrong number of arguments (#{arity} for #{abs[self_arity]})" + end + end + + pproc = self + make_curry = proc do |given_args=[]| + send(type) do |*args| + new_args = given_args + args + if new_args.size >= arity + pproc[*new_args] + else + make_curry[new_args] + end + end + end + make_curry.call + end + +end |