I have such models:
Class User
has_many :comments
# have field 'name' in DB
end
Class Comment
belongs_to :user
end
And i have very complex and very hard for understand admin backend, which gets all models and allows to control it from Admin Interface. It gets all associations and processes it with evals.
And such eval works fine:
eval("comment." + o[0][:object])
where o[0][:object] = "user.name"
But i wanna make it without eval. This approach works, but it's not very universal:
comment.send("user").send("name")
And in real code it looks very ugly:
(o[0][:object].split(".").count < 2) ? h(object.send(o[0][:object])) : h(object.send(o[0][:object].split(".")[0]).send(o[0][:object].split(".")[1]))
So, what's the best way to get eval's univesality for such contructions, if i wanna show more nested calls, like:
comment.user.first_friend.haters.count
???