If in your case there is more use than is presented, this seems like a good place to use OpenStruct :
require 'ostruct' a = OpenStruct.new b = OpenStruct.new aa = 1 ab = 2 b.test1 = 11 [aa, ab, b.test1]
Depending on your use case, you may prefer:
require 'ostruct' class C < OpenStruct
None of the ways you use OpenStruct is an exact parallel to your Python code, but one or the other will probably do everything you need in a cleaner way than instance_variable_set if you don't need it.
source share