Answers:
上课
使用Class.column_names.include? attr_namewhere attr_name是属性的字符串名称。
在这种情况下: Number.column_names.include? 'one'
对于一个实例
使用record.has_attribute?(:attr_name)或record.has_attribute?('attr_name')(Rails 3.2+)或record.attributes.has_key? attr_name。
在这种情况下:number.has_attribute?(:one)或number.has_attribute?('one')或number.attributes.has_key? 'one'
number.has_attribute?它接受一个符号或一个字符串
user,但是user_id由于某些模型委派了用户,因此不得不寻找。
Hash#has_key?不赞成使用Hash#key?
Number.attribute_method? 'one'
Hash#select:number_hash.select { |key, value| Number.column_names.include? key }