下面将列出User类拥有的基础Object类没有的方法...
>> User.methods - Object.methods
=> ["field_types", "maximum", "create!", "active_connections", "to_dropdown",
"content_columns", "su_pw?", "default_timezone", "encode_quoted_value",
"reloadable?", "update", "reset_sequence_name", "default_timezone=",
"validate_find_options", "find_on_conditions_without_deprecation",
"validates_size_of", "execute_simple_calculation", "attr_protected",
"reflections", "table_name_prefix", ...
请注意,methods 是类和类实例的方法。
这是我的 User 类所具有的 ActiveRecord 基类中没有的方法:
>> User.methods - ActiveRecord::Base.methods
=> ["field_types", "su_pw?", "set_login_attr", "create_user_and_conf_user",
"original_table_name", "field_type", "authenticate", "set_default_order",
"id_name?", "id_name_column", "original_locking_column", "default_order",
"subclass_associations", ...
# I ran the statements in the console.
请注意,由于 User 类中定义的(许多)has_many 关系而创建的方法在methods 调用的结果中不。
添加请注意 :has_many 不直接添加方法。相反,ActiveRecord 机器使用 Ruby method_missing 和 responds_to 技术来动态处理方法调用。因此,methods 方法结果中没有列出这些方法。