Pry show methods 命令 returns 意外内容

Pry show methods command returns unexpected content

我试图简单地列出模型的方法。如您所见,returns 出乎意料。我不确定我做错了什么。

    [4] pry(Event):1> ls -m
Object.methods: yaml_tag
ActiveModel::Naming#methods: model_name
ActiveSupport::Benchmarkable#methods: benchmark
ActiveSupport::DescendantsTracker#methods: descendants  direct_descendants
ActiveRecord::ConnectionHandling#methods: clear_cache!  connection_id  connection_id=  mysql2_connection
ActiveRecord::QueryCache::ClassMethods#methods: cache  uncached
ActiveRecord::Querying#methods: 
  any?          distinct     find_each              forty_two   last     pluck       take      
  average       eager_load   find_in_batches        forty_two!  last!    preload     take!     
  calculate     except       find_or_create_by      fourth      limit    readonly    third     
  count         exists?      find_or_create_by!     fourth!     lock     references  third!    
  count_by_sql  fifth        find_or_initialize_by  from        many?    reorder     uniq      
  create_with   fifth!       first                  group       maximum  rewhere     unscope   
  delete        find         first!                 having      minimum  second      update    
  delete_all    find_by      first_or_create        ids         none     second!     update_all
  destroy       find_by!     first_or_create!       includes    offset   select      where     
  destroy_all   find_by_sql  first_or_initialize    joins       order    sum       
ActiveModel::Translation#methods: human_attribute_name
ActiveRecord::Translation#methods: i18n_scope  lookup_ancestors
ActiveRecord::DynamicMatchers#methods: respond_to?
ActiveRecord::Explain#methods: collecting_queries_for_explain  exec_explain
ActiveRecord::Enum#methods: enum
ActiveRecord::Delegation::DelegateCache#methods: initialize_relation_delegate_cache  relation_delegate_class
ActiveRecord::Core::ClassMethods#methods: ===  arel_engine  arel_table  generated_association_methods  inspect
ActiveRecord::Persistence::ClassMethods#methods: create  instantiate
ActiveRecord::ReadonlyAttributes::ClassMethods#methods: attr_readonly  readonly_attributes
ActiveRecord::ModelSchema::ClassMethods#methods: 
  column_names  content_columns         inheritance_column=       reset_sequence_name  table_exists?
  column_types  decorate_columns        initialize_attributes     reset_table_name     table_name=  
  columns       full_table_name_prefix  quoted_table_name         sequence_name    

如何显示该特定模型的方法?

您可以在 pry 控制台中使用 ModelName.methods,它将为您提供 Model 的所有方法。 所以,对你来说,它是:

ls Event.methods

有关更多类似命令,请参阅 here