feature-flags-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePostHog feature flags for Ruby
面向Ruby应用的PostHog功能标志
This skill helps you add PostHog feature flags to Ruby applications.
本技能可帮助你在Ruby应用中添加PostHog功能标志。
Reference files
参考文件
- - Ruby feature flags installation - docs
references/ruby.md - - Adding feature flag code - docs
references/adding-feature-flag-code.md - - Feature flag best practices - docs
references/best-practices.md
Consult the documentation for API details and framework-specific patterns.
- - Ruby功能标志安装文档
references/ruby.md - - 添加功能标志代码文档
references/adding-feature-flag-code.md - - 功能标志最佳实践文档
references/best-practices.md
如需API详情和特定框架的实现模式,请查阅相关文档。
Key principles
核心原则
- Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
- Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.
- Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.
- Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.
- 环境变量:始终使用环境变量存储PostHog密钥,绝不要硬编码。
- 最小改动:在现有逻辑旁添加功能标志代码,不要替换或重构现有代码。
- 优先布尔型标志:除非用户明确要求多变量标志,否则默认使用布尔型标志检查。
- 尽可能服务端处理:优先选择服务端标志评估,以避免UI闪烁问题。
PostHog MCP tools
PostHog MCP工具
Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.
检查是否已连接PostHog MCP服务器。如果已连接,查找与功能标志管理相关的工具(创建、列出、更新、删除标志)。使用这些工具直接在PostHog中管理标志,无需用户手动在控制台操作。
Framework guidelines
框架指南
- posthog-ruby is the Ruby SDK gem name (add to Gemfile) but require it with
gem 'posthog-ruby'(NOTrequire 'posthog')require 'posthog-ruby' - Use PostHog::Client.new(api_key: key, host: host) for instance-based initialization in scripts and CLIs
- In CLIs and scripts: MUST call client.shutdown before exit or all events are lost
- Use begin/rescue/ensure with shutdown in the ensure block for proper cleanup
- capture and identify take a single hash argument: client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' })
- capture_exception takes POSITIONAL args (not keyword): client.capture_exception(exception, distinct_id, additional_properties) — do NOT use keyword syntax
distinct_id:
- posthog-ruby是Ruby SDK的gem包名称(需在Gemfile中添加),但引用时使用
gem 'posthog-ruby'(而非require 'posthog')require 'posthog-ruby' - 在脚本和CLI中,使用进行基于实例的初始化
PostHog::Client.new(api_key: key, host: host) - 在CLI和脚本中:必须在退出前调用,否则所有事件都会丢失
client.shutdown - 使用begin/rescue/ensure结构,并在ensure块中调用shutdown以确保正确清理
- capture和identify方法接受单个哈希参数:
client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' }) - capture_exception方法接受位置参数(而非关键字参数):— 请勿使用
client.capture_exception(exception, distinct_id, additional_properties)关键字语法distinct_id: