标签: ruby instance-variables
我有一个数组["agreement", "user", "client"]。有没有办法将其项目转换为对象@agreement,@user,@client?
["agreement", "user", "client"]
@agreement
@user
@client
答案 0 :(得分:6)
["agreement", "user", "client"] .map{|k| instance_variable_get("@#{k}")}