Ruby 元编程方法列表?

2024-05-26

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


这是来自的最佳答案this https://stackoverflow.com/questions/5127819/is-this-a-comprehensive-list-of-ruby-hook-methods page :

方法相关的钩子

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 http://khelll.com/blog/ruby/ruby-callbacks/博客文章提供了其中许多方法的解释和示例代码。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Ruby 元编程方法列表? 的相关文章

  • 您可以从 MethodInfo 对象获取 Func (或类似的)吗?

    我意识到 一般来说 使用反射会对性能产生影响 实际上 我本人根本不喜欢反思 这纯粹是学术问题 假设存在一些如下所示的类 public class MyClass public string GetName return My Name 请耐
  • 在 Rails 4 中渲染部分/rake 任务/后台作业/模型中的视图

    我读过很多关于在 rake 任务 后台作业 模型中渲染 Rails 部分和视图的内容 我在 Stackoverflow 和网络上找到的绝大多数内容都描述了在 Rails 3 中工作的方法 但它们似乎已经过时了 而且我没有让它们工作 即使花了
  • 在新的 RHEL6 服务器上安装 ruby​​-filemagic gem 时遇到困难

    它似乎正在寻找 libmagic so 1 文件 我有那个文件 它位于 usr lib64 中 我没有以 root 用户身份运行此安装 我也在使用 rvm 和 Bundler 这是我的 bundle 命令的结果 当它到达 Gemfile 中
  • BigDecimal 无法强制转换为 BigDecimal

    这应该很简单 但它却爆炸了 有任何想法吗 d BigDecimal new 2 0 YAML load a gt d to yaml TypeError BigDecimal can t be coerced into BigDecimal
  • 无需别名的 Ruby YAML 编写

    我正在从 ruby 将数据写入 yaml 文件 并且经常在该文件上添加别名 像 id001 somekey somevalue id001 就我而言 我使用 yaml 文件来aid可读性并将名称添加到文件中的值 因为现有数据只是 没有键的分
  • 在 ruby​​ 中读/写受密码保护和加密的文件

    我想加密一个 ruby 程序将从中加载数据的文件 此外 我需要程序在启动时提示输入密码 该密码将用于解密文件 换句话说 该文件需要加密地驻留在计算机上 只有拥有密码的用户才能运行该应用程序 我已经开始研究 openpgp 但据我了解 这仍然
  • Java控制台显示对象的地址而不是实际值[重复]

    这个问题在这里已经有答案了 好的 我正在用 Java 处理一个简单的数组 问题是 当我运行程序时 我得到的是对象的地址而不是实际值 我还发现循环 数组有问题 它应该显示房屋 3 5 和 7 但底部显示的是 3 4 和 5 我哪里出错了 请参
  • Python:动态向对象添加字段

    我想知道是否可以动态向对象添加字段 例如 我希望能够添加如下内容 user object user first name John user last name Smith 当我在 Python 命令行解释器中执行该命令时 我得到 Attr
  • ruby 的 String .hash 方法如何工作?

    我只是红宝石的新手 我见过一个字符串方法 String hash 例如 在irb 我试过了 gt gt mgpyone hash returns gt 144611910 这个方法是如何工作的 The hash方法是为所有对象定义的 看文档
  • 带有附加参数的redirect_to

    我是一个菜鸟 redirect to users url notice Succeed p p 然后我添加一个message它失败了 redirect to users url notice Succeed message test p p
  • 将 Javascript 对象的属性从 string 更改为 int

    我有一个对象数组 每个对象具有三个属性 年份 总计 人均 例子 0 Object per capita 125 8 total 1007 2 year 2009 这些属性是字符串 我想创建一个循环来遍历数组并将它们转换为 int 我尝试了以
  • 什么是 - 获取的是一个目录 - 错误消息

    我收到这个奇怪的错误 Users gideon Documents ca ruby rubytactoe lib player rb 13 in gets Is a directory spec Errno EISDIR 玩家规格 rb r
  • 在编译时查找数组元素位置

    已编辑 大家好 我有一个元素数组 这些元素在程序的所有执行过程中都不会改变 并且其中的项目可以在自己的数组中包含子元素 我必须在处理数组之前准备好它 但是 因为我知道数组不会改变 所以我想将其声明为const 并在编译时准备所有这些 这样我
  • class_eval、class_exec、module_eval 和 module_exec 之间有什么区别?

    我正在读Module文档 但似乎无法理解它们的差异以及应该在哪里使用 怎么样eval不同于exec 我将回答比你的问题更多的内容 包括instance eval exec 在你的问题中 所有变体 instance module class
  • 为什么||和 或 在 Rails 中的行为有所不同? [复制]

    这个问题在这里已经有答案了 可能的重复 i true 和 false 在 Ruby 中是真的吗 https stackoverflow com questions 2802494 i true and false in ruby is tr
  • Ruby gem 环境问题 - LoadError: no such file to load -- robots

    我正在尝试使用 anemone gem 编写一个爬虫 这需要 robots gem 不管出于什么原因 机器人绝对不会包括在内 这是我的一些环境信息 gem list d robots LOCAL GEMS robots 0 10 1 Aut
  • 我必须使用什么加密程序来通过 HTTP 协议发送加密的“电子邮件”和“密码”值?

    我正在使用 Ruby on Rails 3 我想通过 HTTP 协议发送 电子邮件 和 密码 值 我知道 我不应该 但我需要 我需要从发送用户凭据我的客户申请到一个我的服务应用 我可以使用公共和私人RSA密钥来实现这一点 但如果是这样 我不
  • 在 mac os Sierra 上,卡在“设置 CocoaPods 主存储库”上

    转移到 mac os sierra 后 我完全格式化了我的 mac 现在每次运行时我都面临安装 cocoapods 的问题sudo gem install cocoapods pre一切都安装得很好 当我尝试安装 Pod 时 终端堆栈打开S
  • 编译时运算符

    有人可以列出 C 中可用的所有编译时运算符吗 C 中有两个运算符 无论操作数如何 它们的结果始终可以在编译时确定 它们是sizeof 1 and 2 当然 其他运算符的许多特殊用途可以在编译时解决 例如标准中列出的那些整数常量表达式 1 与
  • 用于验证目的的动态查找方法

    我正在使用 Ruby on Rails 3 0 7 我想在运行时查找一些记录以进行验证 但为该查找方法传递 设置一个值 也就是说 在我的班级中 我有以下内容 class Group lt lt ActiveRecord Base valid

随机推荐