在rails中确定方法所属的类 [英] Determine the class to which a method belongs in rails
问题描述
Ap::Application.routes.draw do
resources :accounts
end
我想知道资源"方法所属的类或模块.如果我在 http://apidock.com/rails/(在搜索文本中)搜索资源"方法框提供),将出现一个类列表,其具有方法名称资源".困惑,知道方法的起源.
I want to know the class or module to which the "resources" method belongs. If i search for "resources" method in http://apidock.com/rails/ (in the search text box provided), a list of classes are appearing which has the method name "resources". Confused, with knowing the origin of the method.
是他们的任何命令,我可以在 puts 中使用它来查看来源.
Is their any command which i can use in puts to see the origin.
这个问题有点初学者水平.
The question is bit of beginners level.
谢谢
推荐答案
Ruby 是一种面向对象的语言.虽然方法不是 Ruby 中的对象,但您可以要求 Ruby 为您提供一个表示相关方法的 Method
对象,然后您可以简单地告诉 Method
提供你是它的主人:
Ruby is an object-oriented language. And while methods aren't objects in Ruby, you can ask Ruby to give you a Method
object representing the method in question, and then you can simply tell that Method
to give you its owner:
Ap::Application.routes.draw do
p method(:resources).owner
end
这篇关于在rails中确定方法所属的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!