Skip to content

Instantly share code, notes, and snippets.

@itang
Created August 10, 2015 11:29
Show Gist options
  • Save itang/09fb2011c38f71377f58 to your computer and use it in GitHub Desktop.
Save itang/09fb2011c38f71377f58 to your computer and use it in GitHub Desktop.
Test Crystal macro reflect
macro new_instance(clazz, args)
{{clazz.id}}.new({{*args}})
end
module Util
class A
getter msg
def initialize(@msg)
end
end
end
m = "Hello #{Time.now}"
a = new_instance("Util::A", [m])
puts a.msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment