In Ruby, I have a list of property names like the following:
names = [
:foo,
#...
]
I'd like to iterate through the list and, using reflection, perform conditional assignment on the property name. So, for example, rather than this, which doesn't use reflection:
self.foo ||= 0
I'd like something like something like this:
for name in names
#use local variable "name" to perform assignment using reflection
end
How can I achieve this using Ruby reflection?