Pry gem提供了通过在pry控制台中输入ls -m来查看对象上所有方法的功能。当我在Topic模型上执行ls -m时,它会显示这两种类型的方法
Topic.methods和Topic#方法。有什么不同?
Topic.methods
Topic.methods: _create_callbacks _save_callbacks _update_callbacks _validate_callbacks _validators after_add_for_posts after_add_for_posts= after_add_for_posts? after_remove_for_posts after_remove_for_posts= after_remove_for_posts? before_add_for_posts before_add_for_posts= before_add_for_posts? before_remove_for_posts before_remove_for_posts= before_remove_for_posts? reflections
主题#方法
Topic#methods: _one_time_conditions_valid_12? _one_time_conditions_valid_14? _one_time_conditions_valid_18? _one_time_conditions_valid_22? _one_time_conditions_valid_24? after_add_for_posts after_add_for_posts= after_add_for_posts? after_remove_for_posts after_remove_for_posts= after_remove_for_posts? autosave_associated_records_for_posts autosave_associated_records_for_user before_add_for_posts before_add_for_posts= before_add_for_posts? before_remove_for_posts before_remove_for_posts= before_remove_for_posts? joe validate_associated_records_for_posts
更新
我应该注意,这两种方法只有在我进入第一个Topic实例后才会出现。即cd Topic.first
如果我只进入主题,并执行ls -m,我只看到
Topic.methods