jeudi 7 décembre 2017

Ruby: Access member variable with string (Reflection)

I have a Ruby object User, which has a :first_name member variable. I would like to be able to access that variable with a string.

So if I have a user called u:

u.'first_name' should be equivalent to u.first_name

How could I use reflection to get u.first_name through the string, which is passed in as a variable?





Aucun commentaire:

Enregistrer un commentaire