-
Hello, I'd like to call a method from Crystal in my Ruby code. In the test suite I see that being done with code like this: def class_call_test
puts Anyolite.call_rb_method_of_class(self.class, :class_method_in_ruby, ["World", 4], cast_to: String)
end The problem I am having is that Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, as far as I understand this, you want to call a Ruby class method where the name of the class and the name of the method are known, but the Ruby class has no analogue in Crystal (please correct me otherwise)? It seems that I forgot to actually implement a proper method for this case, so definitely thank you for pointing it out! Until then, you can do something like this: class_name = "TestModule::Test"
method_name = "class_method_in_ruby"
args = ["World", 4]
rb_class = rb.execute_script_line(class_name)
result = Anyolite.call_rb_method_of_object(rb_class, method_name, args, cast_to: String) You get the Ruby class by just putting its name into a script line, which then returns a This does not only work for classes, but all other objects which are somehow accessable from a global context. I hope I could help you, otherwise please feel free to ask. |
Beta Was this translation helpful? Give feedback.
Hi,
as far as I understand this, you want to call a Ruby class method where the name of the class and the name of the method are known, but the Ruby class has no analogue in Crystal (please correct me otherwise)?
It seems that I forgot to actually implement a proper method for this case, so definitely thank you for pointing it out!
I will try to fix this in the next days.
Until then, you can do something like this:
You get the Ruby class by just putting its name into …