class
T
end
arr = {
:a
=>
1
,
:b
=>
2
}
arr.
each
do
|k, v|
T
.class_eval
"def self.#{k.to_s}\n #{v}\n end"
#下述方式效果相同
T
.module_eval
"def self.#{k.to_s}\n #{v}\n end"
end
puts
T
.a # 1
puts T.b # 2