unsafeexternfnrb_say(obj: Value) -> Value {
let name_id =util::rb_intern(str_to_cstring("name").as_ptr());
let ivar_name =class::rb_ivar_get(obj, name_id);
let name =value_to_string(ivar_name);
let message =format!("say, {}", name);
string::rb_utf8_str_new(str_to_cstring(&message).as_ptr(), message.len() as c_long)
}
▶︎ Run bundle exec rake
mkdir -p tmp/x86_64-linux/wasabi/2.7.6
cd tmp/x86_64-linux/wasabi/2.7.6
/opt/hostedtoolcache/Ruby/2.7.6/x64/bin/ruby -I. ../../../../ext/wasabi/extconf.rb
cd -
mkdir -p tmp/x86_64-linux/stage/lib/wasabi
install -c tmp/x86_64-linux/wasabi/2.7.6/wasabi.so lib/wasabi/wasabi.so
cp tmp/x86_64-linux/wasabi/2.7.6/wasabi.so tmp/x86_64-linux/stage/lib/wasabi/wasabi.so
/opt/hostedtoolcache/Ruby/2.7.6/x64/bin/ruby -I/home/runner/work/wasabi/wasabi/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.9.0/lib:/home/runner/work/wasabi/wasabi/vendor/bundle/ruby/2.7.0/gems/rspec-support-3.9.0/lib /home/runner/work/wasabi/wasabi/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.9.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
Wasabi
has a version number
.sum
1 + 2 = 3
.call_to_s
1.to_s
is expected to eq "1"
class with :to_s defined
is expected to eq "foo"
Finished in 0.00192 seconds (files took 0.08639 seconds to load)
4 examples, 0 failures
// 引数の合計数を返す。externfnrb_sum(_mod: Value, a :Value, b: Value) -> Value {
let a =unsafe { fixnum::rb_num2int(a) asi64 };
let b =unsafe { fixnum::rb_num2int(b) asi64 };
let sum = a + b;
unsafe { fixnum::rb_int2inum(sum as SignedValue) }
}
$ bundle exec steep check
# Type checking files:
.....................................................................................................................................................
No type error detected. 🫖