360 Secure SkillHub
360 安全技能中心

Ruby

提供 Ruby 可变字符串、对象比较、块与 lambda、方法可见性、集合、元编程及 Rails 常见陷阱的速查规则和分文件说明,用于辅助编写与排查 Ruby 代码;内容为静态文档,不含执行或验证流程。

ivangdavila
ivangdavila
热度 87.52
最近更新 2026-05-11 15:57:58
分类:开发依赖:纯提示词应用场景:代码生成 / 调试排错 / 概念解释

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add ruby
Metadata
name
Ruby
slug
ruby
version
1.0.1
description
Write reliable Ruby avoiding mutable string traps, block pitfalls, and metaprogramming bugs.
metadata
{"clawdbot":{"emoji":"💎","requires":{"bins":["ruby"]},"os":["linux","darwin","win32"]}}

Quick Reference

Topic File
Mutable strings, object equality objects.md
Proc vs lambda, return behavior blocks.md
Visibility, method_missing methods.md
Array/hash mutation traps collections.md
define_method, eval traps metaprogramming.md
ActiveRecord, N+1, callbacks rails.md

Critical Rules

  • Strings are mutable — s = "hi"; s << "!"; t = s means t also has "!"
  • == vs equal? vs eql? — == value, equal? identity, eql? hash equality
  • Default hash value is shared — Hash.new([]) shares same array, use block form
  • return in proc returns from enclosing method — use lambda for local return
  • Block variable shadows outer scope — x = 1; [2].each { |x| }; x is still 1 (3.0+)
  • method_missing without respond_to_missing? — breaks respond_to? checks
  • private in Ruby is per-object — self.private_method fails, implicit receiver works
  • ||= doesn't work for false/nil distinction — false ||= true replaces false
  • Frozen string literals — # frozen_string_literal: true makes strings immutable
  • Symbol#to_proc — &:method_name only works with no-argument methods
  • rescue => e without type — catches StandardError, not Exception
  • ensure always runs — even after return, use for cleanup