9

I want the Crystal equivalent of this:

clazz = 'ExampleClass'.constantize # Rails
clazz = Object.const_get('ExampleClass') # pure Ruby
obj = clazz.new
Alan Willms
  • 459
  • 1
  • 5
  • 7

1 Answers1

10

You can't, these kind of dynamic aspects are not possible in Crystal.

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

https://github.com/crystal-lang/crystal/issues/949

noraj
  • 3,964
  • 1
  • 30
  • 38
asterite
  • 2,906
  • 1
  • 14
  • 14