跳至主要内容
小龙虾小龙虾AI
🤖

Ruby

Write expressive Ruby with blocks, metaprogramming, and idiomatic patterns.

下载1.6k
星标2
版本1.0.1
写作创作
安全通过

技能说明


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

TopicFile
Mutable strings, object equalityobjects.md
Proc vs lambda, return behaviorblocks.md
Visibility, method_missingmethods.md
Array/hash mutation trapscollections.md
define_method, eval trapsmetaprogramming.md
ActiveRecord, N+1, callbacksrails.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

如何使用「Ruby」?

  1. 打开小龙虾AI(Web 或 iOS App)
  2. 点击上方「立即使用」按钮,或在对话框中输入任务描述
  3. 小龙虾AI 会自动匹配并调用「Ruby技能完成任务
  4. 结果即时呈现,支持继续对话优化

相关技能