2

可能重复:
之间的差异。和 #

Pry gem 提供了通过在 pry 控制台中输入 ls -m 来查看对象上所有方法的能力。当我在主题模型上执行 ls -m 时,它显示了这两种类型的方法

Topic.methods 和 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

主题#methods

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 的第一个实例之后才会出现。即光盘Topic.first

如果我只 cd 进入主题,然后执行 ls -m,我只会看到

Topic.methods
4

0 回答 0