How would I loop over every instance variable “@anything” in a controller? I dont want to loop over one, I want to loop over them as a collection. Ideally scoped to the ones my controller method defines.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
instance_variablesandinstance_variable_get, e.g. like so:Instance variables are scoped to instances, not methods. That’s why they are called instance variables. And they aren’t defined by methods, in fact, they aren’t defined at all: they just spring into existence the first time they are assigned.