从 ruby 中的对象中删除不需要的属性 [英] Remove unwanted attributes from an object in ruby
本文介绍了从 ruby 中的对象中删除不需要的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象,它具有来自调用的 db 的所有属性,可以说:
I have an object that has all the properties from the db from the call lets say:
u = User.find_by_email("email@email.com")
你有first_name
、last_name
、email
、phone
等
如何从对象本身获取除 first_name
和 last_name
之外的所有属性,而不是通过修改对模型的调用?
How can I get all attributes except first_name
and last_name
from the object itself, not by modifying the call to the model?
推荐答案
u.attributes.except("first_name", "last_name")
这篇关于从 ruby 中的对象中删除不需要的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文