加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ruby Metaprogramming方法列表?

发布时间:2020-12-16 21:18:57 所属栏目:百科 来源:网络整理
导读:刚开始学习 Ruby元编程.看看Object.methods我得到: Object.methods = [:allocate,:new,:superclass,:freeze,:===,:==,:=,:,:=,:,:=,:to_s,:included_modules,:include?,:name,:ancestors,:instance_methods,:public_instance_methods,:protected_instance_m
刚开始学习 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博客文章,了解其中许多方法的解释和示例代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读