aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/optional/capi/ext/language_spec.c
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-02-28 19:07:17 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-02-28 19:07:17 +0100
commita0f5ff4c3cd05f8717be2bf1d79f0817f288d398 (patch)
tree441f409cf816cf8a61dacdbaf204ae9f5cbe2f18 /spec/ruby/optional/capi/ext/language_spec.c
parent5d210501825e1682e68cbfc2be424fc339f382fa (diff)
downloadruby-a0f5ff4c3cd05f8717be2bf1d79f0817f288d398.tar.gz
Update to ruby/spec@41bf282
Diffstat (limited to 'spec/ruby/optional/capi/ext/language_spec.c')
-rw-r--r--spec/ruby/optional/capi/ext/language_spec.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/ext/language_spec.c b/spec/ruby/optional/capi/ext/language_spec.c
new file mode 100644
index 0000000000..5aeac63f53
--- /dev/null
+++ b/spec/ruby/optional/capi/ext/language_spec.c
@@ -0,0 +1,34 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static VALUE language_spec_switch(VALUE self, VALUE value) {
+ if (value == ID2SYM(rb_intern("undef"))) {
+ value = Qundef;
+ }
+
+ switch (value) {
+ case Qtrue:
+ return ID2SYM(rb_intern("true"));
+ case Qfalse:
+ return ID2SYM(rb_intern("false"));
+ case Qnil:
+ return ID2SYM(rb_intern("nil"));
+ case Qundef:
+ return ID2SYM(rb_intern("undef"));
+ default:
+ return ID2SYM(rb_intern("default"));
+ }
+}
+
+void Init_language_spec(void) {
+ VALUE cls = rb_define_class("CApiLanguageSpecs", rb_cObject);
+ rb_define_method(cls, "switch", language_spec_switch, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif