gpt4 book ai didi

ruby - Ruby 元编程方法列表?

转载 作者:数据小太阳 更新时间:2023-10-29 06:56:50 28 4
gpt4 key购买 nike

刚开始学习 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_evalinitializemethod_missing?

最佳答案

这是来自 this 的最佳答案页面:

方法相关的钩子(Hook)

method_missing
method_added
singleton_method_added
method_removed
singleton_method_removed
method_undefined
singleton_method_undefined

类和模块 Hook

inherited
append_features
included
extend_object
extended
initialize_copy
const_missing

编码 Hook

marshal_dump
marshal_load

强制 Hook

coerce
induced_from
to_xxx

另外,检查 this博客文章中的许多方法的解释和示例代码。

关于ruby - Ruby 元编程方法列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9490818/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com