For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
预约演示登录免费开始
  • 使用 SDK
    • SDK 概述
    • SDK 如何工作
    • Quickstart
    • Customer showcase
  • 使用 SDK
    • 项目结构
    • 添加自定义代码
    • Migrating to Replay
    • 功能特性
  • 参考
      • Generating an SDK
      • 发布到 RubyGems
      • Ruby 配置
      • 添加自定义代码
      • 变更日志
      • Customer showcase
  • 资源
    • generators.yml
Checking status...
SOC2Soc 2 Type II
© 2026 Fern • Birch Solutions, Inc., a Postman company

Documentation

SDKsDocsAsk FernCLI Reference

API Definitions

OpenAPIAsyncAPIOpenRPCgRPC

Resources

BlogSupportPricing

Company

Brand KitPrivacy PolicyTerms of Service
LogoLogo
预约演示登录免费开始
在本页
  • 添加自定义逻辑
  • 添加自定义 SDK 方法
  • 添加自定义依赖项
参考Ruby

添加自定义代码

||以 Markdown 格式查看|
此页面是否有帮助?
在仪表板中编辑
上一个

Ruby 配置

下一个

Changelog

本页面介绍如何向您的 Ruby SDK 添加自定义逻辑、方法和依赖项。

These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use Replay instead.

添加自定义逻辑

开始添加自定义代码:

1

创建新文件并添加自定义逻辑

lib/<gem_name>/helper.rb
1module YourGem
2 class Helper
3 def self.my_helper
4 puts "Hello World!"
5 end
6 end
7end
2

将文件添加到 .fernignore

.fernignore
1# 指定不应被 Fern 修改的文件
2
3lib/<gem_name>/helper.rb
3

使用辅助方法

Now your users can consume the helper function by importing it from the SDK.

1require "your_gem"
2
3YourGem::Helper.my_helper

添加自定义 SDK 方法

Fern also allows you to add custom methods to the SDK itself (e.g. client.my_method() ) by inheriting the Fern generated client and then extending it.

1

更新 generators.yml 配置

将您的 Fern 生成的客户端命名为 BaseClient 之类的名称,以反映该客户端将被扩展。

generators.yml
1- name: fernapi/fern-ruby-sdk
2 version: 1.12.1
3 config:
4 clientClassName: BaseClient
2

导入并扩展生成的客户端

首先,导入 Fern 生成的基础客户端并扩展它。然后,添加您想要的任何方法。

lib/<gem_name>/my_client.rb
1require_relative "client"
2
3module YourGem
4 class MyClient < BaseClient
5 def my_helper
6 puts "Hello World!"
7 end
8 end
9end
3

更新 .fernignore

将 my_client.rb 添加到 .fernignore。

.fernignore
1+ lib/<gem_name>/my_client.rb
4

使用方法

您的用户需要构造扩展的客户端,而不是生成的客户端。

1require "your_gem"
2
3client = YourGem::MyClient.new

Now your users can consume the helper function by importing it from the SDK.

1client.my_helper

添加自定义依赖项

企业功能

此功能仅适用于企业计划。如需开始使用,请联系 support@buildwithfern.com。

要添加自定义代码所需的 gem,请更新您的 generators.yml。

generators.yml
1- name: fernapi/fern-ruby-sdk
2 version: 1.12.1
3 config:
4 extraDependencies:
5 faraday: ">= 1.0"
6 extraDevDependencies:
7 rspec: "~> 3.0"