Skip to content

Calling Ruby Method from Crystal #12

Answered by Hadeweka
mgomes asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mgomes
Comment options

@Hadeweka
Comment options

@mgomes
Comment options

Answer selected by mgomes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants