You can define an initialize function on your class:
class A
attr_accessor :b,:c,:d
def initialize(h)
h.each {|k,v| public_send("#{k}=",v)}
end
end
Or you can create a module and then "mix it in"
module HashConstructed
def initialize(h)
h.each {|k,v| public_send("#{k}=",v)}
end
end
class Foo
include HashConstructed
attr_accessor :foo, :bar
end
Alternatively you can try something like constructor
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…