0

I have some classes that I want to call dynamiclly:

 Sms::Message::TenMinutesBeforeReminderMessage.new(data).build
Sms::Message::OneHourAfterReminderMessage.new(data).build

I want to be able to do something like this:

send("Sms::Message::#{reminder}ReminderMessage.new(data).build")

Where reminder is a symbol. Is this possible? If so I can't seem to figure out the syntax

1 Answer 1

5

You use constantize from Rails to do it:

klass = "Sms::Message::#{reminder}ReminderMessage".constantize
klass.new(data).build
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.