Skip to content

Commit 9337bf3

Browse files
committed
docs(en,ja): fix splat parameter type annotations
Apply same fixes as Korean docs: - Single splat (*args): `*args: Type` → `*args: Array<Type>` - Double splat (**kwargs): `**kwargs: Type` → `**kwargs: Hash<Symbol, Type>` - Update summary sections with correct type syntax
1 parent 015af97 commit 9337bf3

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

docs/learn/functions/optional-rest-parameters.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ send_email("[email protected]", "Meeting", "[email protected]")
6868
Rest parameters collect multiple arguments into an array. Type the array's element type:
6969

7070
```trb title="rest.trb"
71-
def sum(*numbers: Integer): Integer
71+
def sum(*numbers: Array<Integer>): Integer
7272
numbers.reduce(0, :+)
7373
end
7474
75-
def concat_strings(*strings: String): String
75+
def concat_strings(*strings: Array<String>): String
7676
strings.join(" ")
7777
end
7878
79-
def log_messages(level: String, *messages: String): void
79+
def log_messages(level: String, *messages: Array<String>): void
8080
messages.each do |msg|
8181
puts "[#{level}] #{msg}"
8282
end
@@ -96,7 +96,7 @@ log_messages("INFO", "App started", "Database connected", "Ready")
9696
# [INFO] Ready
9797
```
9898

99-
The type annotation `*numbers: Integer` means "zero or more Integer arguments collected into an array".
99+
The type annotation `*numbers: Array<Integer>` means "zero or more Integer arguments collected into an array".
100100

101101
## Combining Optional and Rest Parameters
102102

@@ -107,7 +107,7 @@ def create_team(
107107
name: String,
108108
leader: String,
109109
active: Boolean = true,
110-
*members: String
110+
*members: Array<String>
111111
): Team
112112
Team.new(
113113
name: name,
@@ -166,12 +166,12 @@ post2 = create_post(
166166
Use double splat `**` to collect keyword arguments into a hash:
167167

168168
```trb title="keyword_rest.trb"
169-
def build_query(table: String, **conditions: String | Integer): String
169+
def build_query(table: String, **conditions: Hash<Symbol, String | Integer>): String
170170
where_clause = conditions.map { |k, v| "#{k} = #{v}" }.join(" AND ")
171171
"SELECT * FROM #{table} WHERE #{where_clause}"
172172
end
173173
174-
def create_config(env: String, **options: String | Integer | Boolean): Config
174+
def create_config(env: String, **options: Hash<Symbol, String | Integer | Boolean>): Config
175175
Config.new(environment: env, options: options)
176176
end
177177
@@ -190,7 +190,7 @@ config = create_config(
190190
)
191191
```
192192

193-
The type annotation `**conditions: String | Integer` means "zero or more keyword arguments with String or Integer values collected into a hash".
193+
The type annotation `**conditions: Hash<Symbol, String | Integer>` means "zero or more keyword arguments with String or Integer values collected into a hash".
194194

195195
## Required Keyword Arguments
196196

@@ -238,10 +238,10 @@ You can combine all parameter types, but they must follow this order:
238238
def complex_function(
239239
required_pos: String, # 1. Required positional
240240
optional_pos: Integer = 0, # 2. Optional positional
241-
*rest_args: String, # 3. Rest parameter
241+
*rest_args: Array<String>, # 3. Rest parameter
242242
required_kw: Boolean, # 4. Required keyword
243243
optional_kw: String = "default", # 5. Optional keyword
244-
**rest_kwargs: String | Integer # 6. Keyword rest
244+
**rest_kwargs: Hash<Symbol, String | Integer> # 6. Keyword rest
245245
): Hash<String, String | Integer | Boolean>
246246
{
247247
"required_pos" => required_pos,
@@ -283,7 +283,7 @@ class HTTPRequestBuilder
283283
end
284284
285285
# Required + rest parameters
286-
def delete(*urls: String): Array<Response>
286+
def delete(*urls: Array<String>): Array<Response>
287287
urls.map { |url| make_request("DELETE", url, nil, {}) }
288288
end
289289
@@ -302,7 +302,7 @@ class HTTPRequestBuilder
302302
def custom_request(
303303
method: String,
304304
url: String,
305-
**headers: String
305+
**headers: Hash<Symbol, String>
306306
): Response
307307
make_request(method, url, nil, headers)
308308
end
@@ -373,18 +373,18 @@ class Logger
373373
end
374374
375375
# Multiple messages with rest parameter
376-
def log_many(level: String, *messages: String): void
376+
def log_many(level: String, *messages: Array<String>): void
377377
messages.each { |msg| log(msg, level) }
378378
end
379379
380380
# Structured logging with keyword rest
381-
def log_structured(message: String, **metadata: String | Integer | Boolean): void
381+
def log_structured(message: String, **metadata: Hash<Symbol, String | Integer | Boolean>): void
382382
meta_str = metadata.map { |k, v| "#{k}=#{v}" }.join(" ")
383383
puts "[INFO] #{message} | #{meta_str}"
384384
end
385385
386386
# Flexible debug logging
387-
def debug(*messages: String, **context: String | Integer): void
387+
def debug(*messages: Array<String>, **context: Hash<Symbol, String | Integer>): void
388388
messages.each do |msg|
389389
ctx_str = context.empty? ? "" : " (#{context.map { |k, v| "#{k}=#{v}" }.join(", ")})"
390390
puts "[DEBUG] #{msg}#{ctx_str}"
@@ -454,7 +454,7 @@ end
454454
### Variadic Factory Functions
455455

456456
```trb title="factory.trb"
457-
def create_users(*names: String, role: String = "user"): Array<User>
457+
def create_users(*names: Array<String>, role: String = "user"): Array<User>
458458
names.map { |name| User.new(name: name, role: role) }
459459
end
460460
@@ -464,7 +464,7 @@ users = create_users("Alice", "Bob", "Charlie", role: "admin")
464464
### Configuration Merging
465465

466466
```trb title="config.trb"
467-
def merge_config(base: Hash<String, String>, **overrides: String): Hash<String, String>
467+
def merge_config(base: Hash<String, String>, **overrides: Hash<Symbol, String>): Hash<String, String>
468468
base.merge(overrides)
469469
end
470470
@@ -480,8 +480,8 @@ config = merge_config(
480480
Optional and rest parameters give your functions flexibility while maintaining type safety:
481481

482482
- **Optional parameters** (`param: Type = default`) have default values
483-
- **Rest parameters** (`*args: Type`) collect multiple arguments into an array
484-
- **Keyword rest** (`**kwargs: Type`) collects keyword arguments into a hash
483+
- **Rest parameters** (`*args: Array<Type>`) collect multiple arguments into an array
484+
- **Keyword rest** (`**kwargs: Hash<Symbol, Type>`) collects keyword arguments into a hash
485485
- T-Ruby ensures type safety for all parameter variations
486486

487487
Master these patterns to write flexible, type-safe APIs that are pleasant to use.

i18n/ja/docusaurus-plugin-content-docs/current/learn/functions/optional-rest-parameters.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ send_email("[email protected]", "Meeting", "[email protected]")
6868
残余パラメータは複数の引数を配列に収集します。配列の要素型を指定します:
6969

7070
```trb title="rest.trb"
71-
def sum(*numbers: Integer): Integer
71+
def sum(*numbers: Array<Integer>): Integer
7272
numbers.reduce(0, :+)
7373
end
7474
75-
def concat_strings(*strings: String): String
75+
def concat_strings(*strings: Array<String>): String
7676
strings.join(" ")
7777
end
7878
79-
def log_messages(level: String, *messages: String): void
79+
def log_messages(level: String, *messages: Array<String>): void
8080
messages.each do |msg|
8181
puts "[#{level}] #{msg}"
8282
end
@@ -96,7 +96,7 @@ log_messages("INFO", "App started", "Database connected", "Ready")
9696
# [INFO] Ready
9797
```
9898

99-
型アノテーション `*numbers: Integer` は「配列に収集される0個以上のInteger引数」を意味します。
99+
型アノテーション `*numbers: Array<Integer>` は「配列に収集される0個以上のInteger引数」を意味します。
100100

101101
## オプショナルパラメータと残余パラメータの組み合わせ
102102

@@ -107,7 +107,7 @@ def create_team(
107107
name: String,
108108
leader: String,
109109
active: Boolean = true,
110-
*members: String
110+
*members: Array<String>
111111
): Team
112112
Team.new(
113113
name: name,
@@ -166,12 +166,12 @@ post2 = create_post(
166166
ダブルスプラット `**` を使用してキーワード引数をハッシュに収集します:
167167

168168
```trb title="keyword_rest.trb"
169-
def build_query(table: String, **conditions: String | Integer): String
169+
def build_query(table: String, **conditions: Hash<Symbol, String | Integer>): String
170170
where_clause = conditions.map { |k, v| "#{k} = #{v}" }.join(" AND ")
171171
"SELECT * FROM #{table} WHERE #{where_clause}"
172172
end
173173
174-
def create_config(env: String, **options: String | Integer | Boolean): Config
174+
def create_config(env: String, **options: Hash<Symbol, String | Integer | Boolean>): Config
175175
Config.new(environment: env, options: options)
176176
end
177177
@@ -190,7 +190,7 @@ config = create_config(
190190
)
191191
```
192192

193-
型アノテーション `**conditions: String | Integer` は「ハッシュに収集されるStringまたはInteger値を持つ0個以上のキーワード引数」を意味します。
193+
型アノテーション `**conditions: Hash<Symbol, String | Integer>` は「ハッシュに収集されるStringまたはInteger値を持つ0個以上のキーワード引数」を意味します。
194194

195195
## 必須キーワード引数
196196

@@ -238,10 +238,10 @@ user2 = register_user(
238238
def complex_function(
239239
required_pos: String, # 1. 必須位置
240240
optional_pos: Integer = 0, # 2. オプショナル位置
241-
*rest_args: String, # 3. 残余パラメータ
241+
*rest_args: Array<String>, # 3. 残余パラメータ
242242
required_kw: Boolean, # 4. 必須キーワード
243243
optional_kw: String = "default", # 5. オプショナルキーワード
244-
**rest_kwargs: String | Integer # 6. キーワード残余
244+
**rest_kwargs: Hash<Symbol, String | Integer> # 6. キーワード残余
245245
): Hash<String, String | Integer | Boolean>
246246
{
247247
"required_pos" => required_pos,
@@ -283,7 +283,7 @@ class HTTPRequestBuilder
283283
end
284284
285285
# 必須 + 残余パラメータ
286-
def delete(*urls: String): Array<Response>
286+
def delete(*urls: Array<String>): Array<Response>
287287
urls.map { |url| make_request("DELETE", url, nil, {}) }
288288
end
289289
@@ -302,7 +302,7 @@ class HTTPRequestBuilder
302302
def custom_request(
303303
method: String,
304304
url: String,
305-
**headers: String
305+
**headers: Hash<Symbol, String>
306306
): Response
307307
make_request(method, url, nil, headers)
308308
end
@@ -373,18 +373,18 @@ class Logger
373373
end
374374
375375
# 残余パラメータで複数メッセージ
376-
def log_many(level: String, *messages: String): void
376+
def log_many(level: String, *messages: Array<String>): void
377377
messages.each { |msg| log(msg, level) }
378378
end
379379
380380
# キーワード残余で構造化ロギング
381-
def log_structured(message: String, **metadata: String | Integer | Boolean): void
381+
def log_structured(message: String, **metadata: Hash<Symbol, String | Integer | Boolean>): void
382382
meta_str = metadata.map { |k, v| "#{k}=#{v}" }.join(" ")
383383
puts "[INFO] #{message} | #{meta_str}"
384384
end
385385
386386
# 柔軟なデバッグロギング
387-
def debug(*messages: String, **context: String | Integer): void
387+
def debug(*messages: Array<String>, **context: Hash<Symbol, String | Integer>): void
388388
messages.each do |msg|
389389
ctx_str = context.empty? ? "" : " (#{context.map { |k, v| "#{k}=#{v}" }.join(", ")})"
390390
puts "[DEBUG] #{msg}#{ctx_str}"
@@ -454,7 +454,7 @@ end
454454
### 可変ファクトリ関数
455455

456456
```trb title="factory.trb"
457-
def create_users(*names: String, role: String = "user"): Array<User>
457+
def create_users(*names: Array<String>, role: String = "user"): Array<User>
458458
names.map { |name| User.new(name: name, role: role) }
459459
end
460460
@@ -464,7 +464,7 @@ users = create_users("Alice", "Bob", "Charlie", role: "admin")
464464
### 設定のマージ
465465

466466
```trb title="config.trb"
467-
def merge_config(base: Hash<String, String>, **overrides: String): Hash<String, String>
467+
def merge_config(base: Hash<String, String>, **overrides: Hash<Symbol, String>): Hash<String, String>
468468
base.merge(overrides)
469469
end
470470
@@ -480,8 +480,8 @@ config = merge_config(
480480
オプショナルパラメータと残余パラメータは、型安全性を維持しながら関数に柔軟性を提供します:
481481

482482
- **オプショナルパラメータ** (`param: Type = default`) はデフォルト値を持ちます
483-
- **残余パラメータ** (`*args: Type`) は複数の引数を配列に収集します
484-
- **キーワード残余** (`**kwargs: Type`) はキーワード引数をハッシュに収集します
483+
- **残余パラメータ** (`*args: Array<Type>`) は複数の引数を配列に収集します
484+
- **キーワード残余** (`**kwargs: Hash<Symbol, Type>`) はキーワード引数をハッシュに収集します
485485
- T-Rubyはすべてのパラメータのバリエーションに対して型安全性を保証します
486486

487487
これらのパターンをマスターして、使いやすい柔軟で型安全なAPIを作成しましょう。

0 commit comments

Comments
 (0)