diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-02-28 19:07:17 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-02-28 19:07:17 +0100 |
commit | a0f5ff4c3cd05f8717be2bf1d79f0817f288d398 (patch) | |
tree | 441f409cf816cf8a61dacdbaf204ae9f5cbe2f18 /spec/ruby/optional/capi/ext/language_spec.c | |
parent | 5d210501825e1682e68cbfc2be424fc339f382fa (diff) | |
download | ruby-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.c | 34 |
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 |