ruby:如何获取当前类而不是基类中定义或覆盖的所有方法?

发布于 2024-12-23 01:56:06 字数 213 浏览 1 评论 0原文

有谁如何获取当前类而不是基类中定义或覆盖的所有方法? 例如,

class MyBase
  def Test
  end
end

class MyDerived
  def Test1
  end
end

当我调用 MyDerived.methods 时,我得到了很多方法,但我只想得到“Test1”,因为它是它自己的方法,这可能吗? 谢谢。

Does anyone how to get all the methods that are defined or overwrited in current class rather than base class?
e.g.

class MyBase
  def Test
  end
end

class MyDerived
  def Test1
  end
end

When I call MyDerived.methods, i got a lot of methods, but I only want to get 'Test1' because it is its own method, is it possible?
thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把梦留给海 2024-12-30 01:56:06
class Foo
  def bar
  end
end

Foo.new.public_methods false

=> [:bar]
class Foo
  def bar
  end
end

Foo.new.public_methods false

=> [:bar]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文