码迷,mamicode.com
首页 > 其他好文 > 详细

私有方法的查找方式

时间:2016-03-24 20:01:49      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

 

    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]

 

私有方法的查找方式

标签:

原文地址:http://www.cnblogs.com/iwangzheng/p/5316792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!