将字符串转换为实例变量

时间:2015-04-02 10:01:31

标签: ruby instance-variables

我有一个数组["agreement", "user", "client"]。有没有办法将其项目转换为对象@agreement@user@client

1 个答案:

答案 0 :(得分:6)

["agreement", "user", "client"]
.map{|k| instance_variable_get("@#{k}")}