ruby - "do | |"在 Ruby 中是什么意思?

标签 ruby

在阅读一些 Ruby 代码时,我看到了这个:

create_table :talks do |t|

|variable| 这个符号是什么?那有什么作用?

此外,我在哪里可以找到这些特定主题的帮助,例如 | |#{} 等等?

最佳答案

这是一种为 block 定义参数的方法,类似于def methodname(arg1, arg2)

有一个很好的 block 解释 from Robert Sosinski

关于ruby - "do | |"在 Ruby 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836820/

相关文章:

ruby-on-rails - 如何检查 `Integer` 是否大于另一个 `Integer` "easily"/"efficiently"?

ruby - 从 rake 运行时测试失败,直接运行时通过

Ruby 二维数组 : finding an object's coordinates

Ruby 的变量交换 : x, y = y,x -- 数组引用似乎更慢?

ruby - 安装 ffi 时出错

mysql - Rails 使用多个数据库

ruby-on-rails - 了解 Rails 中的委托(delegate)和作用域方法

arrays - Elasticsearch 按数组列排序

sql - 如何列出用户可用的所有任务?

ruby - 在不破坏 anchor 和别名的情况下读写 YAML 文件?