How to instantiate a class from a string name in Crystal?

I want to get the equivalent of Crystal:

clazz = 'ExampleClass'.constantize # Rails clazz = Object.const_get('ExampleClass') # pure Ruby obj = clazz.new 
+6
source share
1 answer

You cannot, these dynamic aspects are not possible in Crystal.

However, macros can go a long way. Please read this similar issue and discussion:

https://github.com/manastech/crystal/issues/949

+9
source

All Articles