This is a Ruby question though I use it in a Rails context.
I need to call a method where I use string variables to assign values to its keys (parameter names).
For instance I got :
MyRailsModelClass.where(key_of_my_method: my_value)
I want to make this more dynamic.
I can create a MyRailsModelClass like this “my_rails_model_class”.classify
I need to make key_of_my_method more dynamic and replace it with a variable.
I’m thinking about something like :
"my_rails_model_class".classify.where(my_key.to_sym => my_value)
Does anybody has a clue ?
Thanks
Actually, classify method is not enough. You need to constantize before to apply any class method.
I solved it this way (because it is much more efficient; while classify do call many more methods : camelize(singularize(table_name.to_s.sub() ) :
but you could do it the longuer way :