Reputation: 403
How can I change the value of the field of composite type using Symbol
or String
?
Example: If I have MyType
,
type MyType
x
end
mt=MyType(0)
I know I can change the value by mt.x=1
.
However, how can I do the same thing using a variable changed_fieldname = :x
or changed_fieldname = x
?
I don't want to directly write the name of the field as mt.x=1
.
Upvotes: 5
Views: 63