Debian Codegraph @

ext/-test-/exception/ensured.c

raw
1 #include <ruby.h>
2
3 static VALUE
4 begin(VALUE object)
5 {
6 return rb_funcall(object, rb_intern("try_method"), 0);
7 }
8
9 static VALUE
10 ensure(VALUE object)
11 {
12 return rb_funcall(object, rb_intern("ensured_method"), 0);
13 }
14
15 static VALUE
16 ensured(VALUE module, VALUE object)
17 {
18 return rb_ensure(begin, object, ensure, object);
19 }
20
21 static VALUE
22 exc_raise(VALUE exc)
23 {
24 rb_exc_raise(exc);
25 return Qnil;
26 }
27
28 static VALUE
29 ensure_raise(VALUE module, VALUE object, VALUE exc)
30 {
31 return rb_ensure(rb_yield, object, exc_raise, exc);
32 }
33
34 void
35 Init_ensured(VALUE klass)
36 {
37 rb_define_module_function(klass, "ensured", ensured, 1);
38 rb_define_module_function(klass, "ensure_raise", ensure_raise, 2);
39 }