Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change String "@patient" to variable

How can i use strings as varibles in ruby and assign values to it for eg:

"@" + "Patient".downcase = Patient.all.last

Thanks!

like image 785
John Smith Avatar asked Apr 13 '26 23:04

John Smith


1 Answers

If you mean instance variables, you can do this:

instance_variable_set('@' + 'Patient'.downcase, Patient.last)
like image 169
Marek Lipka Avatar answered Apr 16 '26 13:04

Marek Lipka