• 私有方法的查找方式


        59: def adjust_sequence
     => 60:   binding.pry
        61:   self.class.
        62:     where(sortable_conditions).
        63:     where('sequence > ?',sequence).update_all("sequence = sequence - 1")
        64: end
    [1] pry(#<RecommendedVideo>)> sortable_conditions
    => {}
    [2] pry(#<RecommendedVideo>)> super.sortable_conditions
    NoMethodError: super: no superclass method `adjust_sequence' for #<RecommendedVideo:0x007f11ef8971e8>
    from /home/wz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activemodel-4.2.5/lib/active_model/attribute_methods.rb:430:in `method_missing'
    [3] pry(#<RecommendedVideo>)> self
    => #<RecommendedVideo:0x007f11ef8971e8
     id: 28,
     video_id: "XODI0OA==",
     url: "",
     title: "最美是你 TV版",
     video_type: "show",
     version: "",
     homepage_channel_id: "2",
     created_by: "",
     updated_by: "",
     current_update: "",
     show_id: "ad054ed6d9e911e0a046",
     pay_type: "0",
     paid: "0",
     state: 0,
     sequence: 1,
     created_at: Thu, 24 Mar 2016 18:27:05 CST +08:00,
     updated_at: Thu, 24 Mar 2016 18:56:23 CST +08:00>
    [4] pry(#<RecommendedVideo>)> self.sortable_conditions
    NoMethodError: private method `sortable_conditions' called for #<RecommendedVideo:0x007f11ef8971e8>
    from /home/wz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activemodel-4.2.5/lib/active_model/attribute_methods.rb:430:in `method_missing'

    原因是私有方法不能显示的调用

    [14] pry(#<RecommendedVideo>)> self.send :sortable_conditions
    => {}

    查看方法调用及方法所在处

    [10] pry(#<RecommendedVideo>)> self.class.instance_method :sortable_conditions
    => #<UnboundMethod: RecommendedVideo#sortable_conditions>
    [11] pry(#<RecommendedVideo>)> m = self.class.instance_method :sortable_conditions
    => #<UnboundMethod: RecommendedVideo#sortable_conditions>
    [12] pry(#<RecommendedVideo>)> m.source
    => "    def sortable_conditions
          {}
        end
    "
    [13] pry(#<RecommendedVideo>)> m.source_location
    => ["/home/wz/workspace/ott-remote-cms/app/models/recommended_video.rb", 123]
  • 相关阅读:
    c# linq查询的等于大于符号是什么意思?
    c# Socket tcpClient处理连接超时方式timeout
    不同网段服务器与客户端连接问题解决方法TCP/IP_C/S
    Http请求响应及SpringMVC相关注解解析
    Nginx部署项目,转发规则,负载均衡配置
    Linux redis设置后台启动
    Linux centos7安装Jdk nginx redis
    SpringCloud整合SpringSecurity JWT进行认证 ,鉴权
    C#中class与struct的区别概述
    列举ASP.NET 页面之间传递值的几种方式
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/5316792.html
Copyright © 2020-2023  润新知