微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ruby Metaprogramming方法列表?

刚开始学习 Ruby元编程.看看Object.methods我得到:
Object.methods => [
:allocate,:new,:superclass,:freeze,:===,:==,:<=>,:<,:<=,:>,:>=,:to_s,:included_modules,:include?,:name,:ancestors,:instance_methods,:public_instance_methods,:protected_instance_methods,:private_instance_methods,:constants,:const_get,:const_set,:const_defined?,:const_missing,:class_variables,:remove_class_variable,:class_variable_get,:class_variable_set,:class_variable_defined?,:module_exec,:class_exec,:module_eval,:class_eval,:method_defined?,:public_method_defined?,:private_method_defined?,:protected_method_defined?,:public_class_method,:private_class_method,:autoload,:autoload?,:instance_method,:public_instance_method,:nil?,:=~,:!~,:eql?,:hash,:class,:singleton_class,:clone,:dup,:initialize_dup,:initialize_clone,:taint,:tainted?,:untaint,:untrust,:untrusted?,:trust,:frozen?,:inspect,:methods,:singleton_methods,:protected_methods,:private_methods,:public_methods,:instance_variables,:instance_variable_get,:instance_variable_set,:instance_variable_defined?,:instance_of?,:kind_of?,:is_a?,:tap,:send,:public_send,:respond_to?,:respond_to_missing?,:extend,:display,:method,:public_method,:define_singleton_method,:__id__,:object_id,:to_enum,:enum_for,:equal?,:!,:!=,:instance_eval,:instance_exec,:__send__]

是否有一个对元编程有用的方法列表?例如instance_eval,initialize和method_missing?

解决方法

以下是 this页面的最佳答案:

方法相关的钩子

method_missing
method_added
singleton_method_added
method_removed
singleton_method_removed
method_undefined
singleton_method_undefined

班级&模块挂钩

inherited
append_features
included
extend_object
extended
initialize_copy
const_missing

编组挂钩

marshal_dump
marshal_load

强制钩子

coerce
induced_from
to_xxx

另外,请查看this博客文章,了解其中许多方法的解释和示例代码.

原文地址:https://www.jb51.cc/ruby/267637.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐