私有方法的查找方式

    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\n      {}\n    end\n"
[13] pry(#<RecommendedVideo>)> m.source_location
=> ["/home/wz/workspace/ott-remote-cms/app/models/recommended_video.rb", 123]



你可能感兴趣的:(私有方法的查找方式)