---
title: "ruby | 今日所学 | OOZOU"
description: "来自 OOZOU 团队的简短实用 ruby 笔记。"
canonical: https://oozou.com/zh-Hans/til-topics/ruby
locale: zh-Hans
---

# ruby | 今日所学

> 来自 OOZOU 团队的简短实用 ruby 笔记。

- [让 Pry 支持粘贴使用行首点记法的多行 Ruby 区块](https://oozou.com/zh-Hans/til/allow-pasting-multiline-ruby-blocks-in-pry-when-using-leading-dot-notation-116) ([markdown](https://oozou.com/zh-Hans/til/allow-pasting-multiline-ruby-blocks-in-pry-when-using-leading-dot-notation-116.md)) (2021-04-30): 我们现在很常使用行首点记法，例如
- [不含插值的 Heredoc](https://oozou.com/zh-Hans/til/heredoc-without-interpolation-74) ([markdown](https://oozou.com/zh-Hans/til/heredoc-without-interpolation-74.md)) (2020-10-14): 有时你想用 Ruby 的 Heredoc，但不希望它做插值（'#{....}'）。只要给你的标识符加上一对单引号就能做到：
- [在 Ruby 中自动创建中间层的 Hashtable](https://oozou.com/zh-Hans/til/automagical-intermediate-level-hashtables-in-ruby-62) ([markdown](https://oozou.com/zh-Hans/til/automagical-intermediate-level-hashtables-in-ruby-62.md)) (2020-10-13): 所有中间层的 hashtable 都会魔法般地自动创建出来
- [用 rbenv 为单条命令切换 Ruby 版本](https://oozou.com/zh-Hans/til/change-ruby-version-for-single-command-with-rbenv-68) ([markdown](https://oozou.com/zh-Hans/til/change-ruby-version-for-single-command-with-rbenv-68.md)) (2020-10-13): 你可以用 rbenv local 暂时切换 Ruby 版本
- [把 VS Code 的 Go to definition 改成 Cmd+Click](https://oozou.com/zh-Hans/til/change-vs-code-go-to-definition-to-cmd-click-59) ([markdown](https://oozou.com/zh-Hans/til/change-vs-code-go-to-definition-to-cmd-click-59.md)) (2020-10-13): 只要打开你的用户设置 JSON 文件，加上这个选项：
- [提升 Bundler 性能](https://oozou.com/zh-Hans/til/improve-bundler-performance-56) ([markdown](https://oozou.com/zh-Hans/til/improve-bundler-performance-56.md)) (2020-10-13): 通过用多个 job 并行运行 bundler 任务来提升 bundler 性能：
- [optional relation + RSpec 搭配 shoulda-matchers](https://oozou.com/zh-Hans/til/optional-relation-rspec-w-shoulda-matchers-41) ([markdown](https://oozou.com/zh-Hans/til/optional-relation-rspec-w-shoulda-matchers-41.md)) (2020-10-13): User 1 - 0..1 Laptop
- [移除 ruby 2.6 内置的 bundler](https://oozou.com/zh-Hans/til/remove-ruby-2-6-bundled-bundler-39) ([markdown](https://oozou.com/zh-Hans/til/remove-ruby-2-6-bundled-bundler-39.md)) (2020-10-13): 在已安装 bundler v2 的情况下用 ruby 2.6+ 生成 rails 6 应用，会创建无法使用的 binstubs。如果你看到这个错误 You must use Bundler 2 or greater with this lockfile. 你可以移除…
- [对你当前的 branch 运行 rubocop](https://oozou.com/zh-Hans/til/run-rubocop-against-your-current-branch-21) ([markdown](https://oozou.com/zh-Hans/til/run-rubocop-against-your-current-branch-21.md)) (2020-10-13): 对你当前的 branch 运行 rubocop
- [在 commit 之前运行 rubocop](https://oozou.com/zh-Hans/til/run-rubocop-before-commit-8) ([markdown](https://oozou.com/zh-Hans/til/run-rubocop-before-commit-8.md)) (2020-10-13): Git hooks 对于在 Git repository 中自动化任务、落实代码规范来说非常强大。Git hooks 的一个常见用途，就是在允许 commit 之前先运行自动化测试和代码分析工具…
- [抑制 rspec 警告](https://oozou.com/zh-Hans/til/suppress-rspec-warnings-33) ([markdown](https://oozou.com/zh-Hans/til/suppress-rspec-warnings-33.md)) (2020-10-13): $ RUBYOPT=W0 bundle exec rspec spec/ ...
- [FactoryBot 也可以用在非 ActiveRecord 的 model 上](https://oozou.com/zh-Hans/til/you-can-use-factorybot-for-non-activerecord-models-45) ([markdown](https://oozou.com/zh-Hans/til/you-can-use-factorybot-for-non-activerecord-models-45.md)) (2020-10-13): 你可以用 FactoryBot 的 initialize\with* 方法，以任何你想要的方式初始化对象，让你能随心所欲地为任何对象创建 factory

All notes: [今日所学](https://oozou.com/zh-Hans/til) ([markdown](https://oozou.com/zh-Hans/til.md)).

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hans/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
