Ruby Metaprogramming方法列表?

前端之家收集整理的这篇文章主要介绍了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.f2er.com/ruby/267637.html

猜你在找的Ruby相关文章